|
-
April 16th, 2012, 02:11 PM
#1
compass angle prediction question
Hello,
In a cartesian coordinate system, I want to be able to predict a compass angle of an object. So I have a base position of (0,0) and then a distance and compass angle to an object. This object also has a heading and a speed. How can I predict the new compass angle of the object with that information?
my coordinate system is like this:
Code:
0 y
|
|
270-------------- 90 x
|
|
180
I think the first step would be to compute the cartesian coordinates of the object:
float degs_to_rads = 3.141592653589793 / 180.0;
x = distance * sin(angle*degs_to_rads);
y = distance * cos(angle*degs_to_rads);
then the next step would be to compute the predicted x and y from the speed and heading of the object:
predictedx = ??
predictedy = ??
then finally convert back to an angle, and distance:
newDistance = sqrt(predictedx^2 + predictedy^2);
newAngle = atan2(predictedy, predictedx);
Can anyone help me fill in the blanks?? Are my other things correct?
Thanks!
Alex
Last edited by aseminov; April 16th, 2012 at 02:56 PM.
-
April 16th, 2012, 02:28 PM
#2
Re: compass angle prediction question
Your coordinate system is incorrect C++, like most programming languages use radians for trig functions.
Code:
0 y
|
|
3pi/2-------------- pi/2 x
|
|
pi
-
April 16th, 2012, 02:36 PM
#3
Re: compass angle prediction question
ok so say I convert angle to radians.. then what?
-
April 16th, 2012, 03:04 PM
#4
Re: compass angle prediction question
Hi, IRC guy here. So what you want to do is compute the displacement vector v = (x',y') that you will add to your old coordinates to get the new point. Now, given your distance d (say your speed for 1 second) and your heading t, you will have v = (d*cos(t),d*sin(t)). Just add this to your old vector to get your predicted vector.
In other words,
predictedx = x + d*cos(t)
predictedy = y + d*sin(t)
-
April 16th, 2012, 04:00 PM
#5
Re: compass angle prediction question
The displacement vector needs to depend on delta-t. It won't always be 1 unit of time.
-
April 16th, 2012, 04:56 PM
#6
Re: compass angle prediction question
Can you elaborate Lindley?
Thanks,
Alex
-
April 16th, 2012, 05:01 PM
#7
Re: compass angle prediction question
Just look at the units. I don't know what your units are, but for argument let's say meters and seconds.
You have a position (m) and a velocity (m/s). You also have a delta_time (s). You know that your displacement vector has to have units of m, therefore clearly it has to be m/s*s = m, or velocity*delta_time.
-
April 16th, 2012, 05:36 PM
#8
Re: compass angle prediction question
I said 1 second because that's what we talked about in IRC, but yeah d = seconds*speed.
-
April 17th, 2012, 12:20 AM
#9
Re: compass angle prediction question
 Originally Posted by aseminov
Are my other things correct?
You're in trouble because you've chosen a non-standard angle definition. There a two so called principal angle definitions for a 2D Cartesian coordinate system but this is the one most in use I think,
Code:
90 y
|
|
+-180-------------- 0 x
|
|
-90
By adopting this standard everything becomes so much easier. It's used in textbooks, handbooks, standard libraries and generally assumed in discussions.
The relation between angle, distance and position coordinates will be,
x = distance * cos(angle)
y = distance * sin(angle)
The inverse will be,
distance = sqrt(x*x + y*y)
angle = atan2(y,x)
And the prediction formula suggested by sifgfisdogjjpgij is now correct,
predictedx = x + d*cos(t)
predictedy = y + d*sin(t)
But of course you can still express standard angles in other definitions, and back again. It's a simple (piecewise) linear relationship as I explaned in one of your previous threads. So use standard angles for calculation (in radians throughout) and your own angle definition for presentation.
Last edited by nuzzle; April 17th, 2012 at 04:37 AM.
-
April 17th, 2012, 06:18 AM
#10
Re: compass angle prediction question
Hello Nuzzle,
I think if I just reverse the sin's and cos's and reverse x and y in the atan2() the code all works. Correct?
Thanks!
Alex
Last edited by aseminov; April 17th, 2012 at 07:40 AM.
-
April 17th, 2012, 10:02 AM
#11
Re: compass angle prediction question
 Originally Posted by aseminov
I think if I just reverse the sin's and cos's and reverse x and y in the atan2() the code all works. Correct?
That should work in theory. Your angle definition means you're shifting the trigonometric functions PI/2 degrees to the right and then negating the angle. If you do that cos becomes sin and sin becomes cos indeed.
But you're still using standard functions that are designed to work with a standard coordinate system. So in practice you still need to be very careful making sure results become correctly mapped to your angle definition.
I just don't see why you have to introduce the additional complication of mixing standard coordinates with non-standard angles that are rotated and reversed? But it's your call. Please go ahead and shoot yourself in the foot.
Last edited by nuzzle; April 18th, 2012 at 01:47 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|