Angle difference
#2
(01-31-2023, 05:04 PM)bplus Wrote: I was working collisions of spiders and 2 spiders going in same direction or nearly so needed collision code different from spiders coming head on or perpendicular to each other.

So how do I tell if spiders are going in same direction or nearly so, say their headings are within 30 degrees of each other or not?

Just subtract the angles right? Or take the ABS of the difference right?

Well what if one has a heading of 0 degrees and the other a heading of 350 degrees the difference is 350, I am wanting 10 degrees so make 0 360 instead, easy right?

So now what if one was x and the other y when do I know to add 360? like with 0.

I came up with a function AngleDifference to handle this because this issue has come up before but it seems kind of clunky. I think the time before I used Major and Minor arc differences, two answers to angle difference. This time one answer but again seems cluncky.

I won't show my code because I don't want to bias someone coming up with maybe a more elegant solution which I suspect exists.

So if you can do it in a line or 2 I'd be interested.

Hi ! I know the problem. I've been using this for a long time and it works.

"unit" is the unit of measure expressing a complete revolution. If you count in 360, write 360! If 2*_pi -t, then 2*_pi !

Code: (Select All)
Function dif_ang (a, b, unit): a2 = a: b2 = b
    Do While Abs(a2 - b2) > Abs((a2 - unit) - b2): a2 = a2 - unit: Loop: Do While Abs(a2 - b2) > Abs((a2 + unit) - b2): a2 = a2 + unit: Loop: dif_ang = a2 - b2
End Function
Reply


Messages In This Thread
Angle difference - by bplus - 01-31-2023, 05:04 PM
RE: Angle difference - by MasterGy - 01-31-2023, 05:50 PM
RE: Angle difference - by OldMoses - 01-31-2023, 06:15 PM
RE: Angle difference - by bplus - 01-31-2023, 06:44 PM
RE: Angle difference - by OldMoses - 01-31-2023, 07:33 PM
RE: Angle difference - by bplus - 01-31-2023, 08:12 PM
RE: Angle difference - by OldMoses - 01-31-2023, 10:32 PM
RE: Angle difference - by SMcNeill - 01-31-2023, 09:29 PM
RE: Angle difference - by bplus - 01-31-2023, 10:03 PM



Users browsing this thread: 2 Guest(s)