Calculate car angle on the route

  • Thread starter Thread starter hladon
  • Start date Start date
  • Tags Tags
    Angle Car
AI Thread Summary
To calculate the angle of a car's movement vector in a 2D scene, using the atan2 function is recommended over arccos for better accuracy. The original approach led to erratic behavior of the car image when too many points were present on the route. The atan2 function, specifically atan2(y2 - y1, x2 - x1), provides a more stable angle calculation. This adjustment should eliminate the "dancing" effect observed with the previous method. Implementing this change will enhance the visual representation of the car's movement on the track.
hladon
Messages
1
Reaction score
0
I am writing program which displays car movement through recorded track(2D scene).
So I have a set of points (x1, y1), (x2, y2), (x3, y3), ...(xk, yk), from which track consits.
And I need to calculate an angle between car movement vector and OX(or OY) axis so I could then rotate car image on correct angle.


y_e5bc1c3d.jpg
I tried to solve this problem by calculating angle as follows:

alpha = arccos( Yk / sqrt( x^2 + Yk^2 ) );

But looks like it's not the perfect solution, because if there is too much points on the route then car image starts dancing through the route:)

I also tried to compute angle between surely different points but the quantity of route points on the square inch can be changed dynamically in my program so if there's too much points, car is rotated really awful :(


Any ideas?
Thanks in advance,
Alex
 
Last edited:
Physics news on Phys.org
hladon said:
alpha = arccos( Yk / sqrt( x^2 + Yk^2 ) )
How did you arrive at this equation?
Show your coordinate reference on your drawing.
Have you computed the angles manually? Do they match your expectations? Please show these results.

But looks like it's not the perfect solution, because if there is too much points on the route then car image starts dancing through the route:)
Not very descriptive. Are you saying it works fine with fewer points? How many?
 
Hi hladon! Welcome to PF! :smile:

arccos won't do everything you want it to do.

To calculate alpha properly, you need the atan2 function, which is defined in the various computer languages.
There are 2 variants of it: the atan2(x,y) function and the atan2(y,x) function.

Since you didn't specify which computer language you use, you'll have to find out which variant you have.

To calculate the proper angle, you'll need something like:

alpha = atan2(x2 - x1, y2 - y1)

That should stop the dancing! :wink:


Cheers! :smile:
 
Thread 'Variable mass system : water sprayed into a moving container'
Starting with the mass considerations #m(t)# is mass of water #M_{c}# mass of container and #M(t)# mass of total system $$M(t) = M_{C} + m(t)$$ $$\Rightarrow \frac{dM(t)}{dt} = \frac{dm(t)}{dt}$$ $$P_i = Mv + u \, dm$$ $$P_f = (M + dm)(v + dv)$$ $$\Delta P = M \, dv + (v - u) \, dm$$ $$F = \frac{dP}{dt} = M \frac{dv}{dt} + (v - u) \frac{dm}{dt}$$ $$F = u \frac{dm}{dt} = \rho A u^2$$ from conservation of momentum , the cannon recoils with the same force which it applies. $$\quad \frac{dm}{dt}...
Back
Top