If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

heading in a cartesian coordinate system question

Hello,

I have 2 points in a cartesian coordinate system, where the first point is always (0,0). Given the second point and a heading in degrees, how would I write an algorithm to determine if the 2nd point is traveling in the general direction of (0,0) ?

For example:

Point a (0,0)
Point b (10,0)
Point b heading = 270 degrees

This would be true this 270 degrees points right and point b is 10 units right of point a. I would probably also want this is be fuzzy somewhat, in that anything from say + or - 30 degrees would also be true, or something like this.

Does there exist any known algorithms, implemented in C++, to help me with this problem?

Re: heading in a cartesian coordinate system question

Originally Posted by aseminov

For example:

Point a (0,0)
Point b (10,0)
Point b heading = 270 degrees

This would be true this 270 degrees points right and point b is 10 units right of point a.

I don't quite get your definition of heading. With a heading of 270 degrees point b is headed straight south isn't it? It means it must be somewhere on the positive y-axis to be going towards a, like at (0,10) or something.

The problem itself is basic trigonometry: Determine the heading of the vector starting at b ending at a. That's the heading b must have to end up at a (travelling along a straight line).

Re: heading in a cartesian coordinate system question

I don't quite get your definition of heading. With a heading of 270 degrees point b is headed straight south isn't it? It means it must be somewhere on the positive y-axis to be going towards a, like at (0,10) or something.

If xX is horizontal and Y is vertical, then 10, 0 is 10 units to the right of 0,0 alnong the X axis. A 270 degree heading would be due West. And point straight to 0,0.

The problem itself is basic trigonometry: Determine the heading of the vector starting at b ending at a. That's the heading b must have to end up at a (travelling along a straight line).

Re: heading in a cartesian coordinate system question

If xX is horizontal and Y is vertical, then 10, 0 is 10 units to the right of 0,0 alnong the X axis. A 270 degree heading would be due West. And point straight to 0,0.

No, 270 degrees would not be due west, 180 would.

Making a 180 degree turn means going in the opposite direction. If you're starting at origo travelling eastward and then make a 180 degree turn you will be going westward back toward origo. 270 degrees would mean going south (as does also -90 degrees).

Re: heading in a cartesian coordinate system question

Understand that you are using a compass-style definition of headings, which differs from standard angular measurements used by most trig functions by direction (clockwise vs. counterclockwise) and by 90 degrees (or, pi/2 radians, since most trig functions use radians, not degrees).

With that understanding, look at the atan2() function. To get the compass heading in degrees from point b to point a, use the following: