realbasic-games
[Top] [All Lists]

Incrementing or decrementing a heading in radians

To: <realbasic-games at lists dot realsoftware dot com>
Subject: Incrementing or decrementing a heading in radians
From: "Martin Dillon" <martin dot dillon at optusnet dot com dot au>
Date: Tue, 30 Aug 2005 22:42:49 +1000
Delivered-to: realbasic-games at lists dot realsoftware dot com
I'm using a Canvas as a 2D cartesian plane. I have a creature travelling in the 
direction of random heading H (expressed in radians).  Every so often it pauses 
at a random point x1,y1 and then needs to change the value of H to make it move 
towards a random point x2,y2.  It then repeats this indefinitely moving to new 
random points.

I can compute the direction D (in radians) from one point to the other OK.
I can compute the side (left or right) of the heading H that x2,y2 falls on OK.

I'm having trouble computing a turn_amount T in radians that I can increment to 
H (turning right relative to H) or decrement from H (turning left relative to 
H).  I seem  to get incorrect results when x2,y2 falls within certain quadrants 
relative to x1,y1 for certain headings.

I'm sure this should be simple and I must be missing something.  I'd be 
grateful for any pseudocode suggesting ways to compute a value for T that can 
be added or subtracted from H to give my creature the new heading it needs.

Note that I want my creature to turn left or right as appropriate to get to 
x2,y2 - rather than needlessly turning more than pi radians (180 degrees).

Thanks,
Martin
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>