Calculate car angle on the route

  • Thread starter hladon
  • Start date
  • Tags
    Angle Car
In summary, the author is trying to solve a problem where car movement is affected by too many points on the recorded track. He tried various methods, but found that the best solution was to use the atan2 function to calculate the angle between car movement vector and the OX or OY axis.
  • #1
hladon
1
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
  • #2
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?
 
  • #3
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:
 

1. How do you calculate the angle of a car on a route?

To calculate the angle of a car on a route, you will need to know the distance and height of the route. Then, you can use the trigonometric function tangent to find the angle, using the formula angle = arctan(height/distance).

2. What is the importance of calculating the car angle on a route?

Knowing the car angle on a route is important for ensuring safe navigation and avoiding accidents. It also helps in planning routes and determining the most efficient path for a car to take.

3. Can you calculate the car angle on a route without knowing the height of the route?

No, it is not possible to calculate the car angle on a route without knowing the height of the route. The height is a crucial component in the formula for finding the angle, and without it, the calculation would not be accurate.

4. How does the car angle on a route affect gas mileage?

The car angle on a route can greatly affect gas mileage. If the route has a steep incline, the car will have to use more power to climb, thus using more gas. Similarly, the car may use less gas going down a steep decline. Therefore, knowing the car angle on a route can help in planning fuel-efficient routes.

5. Are there any tools or technologies to help calculate the car angle on a route?

Yes, there are various tools and technologies available to help calculate the car angle on a route. Some modern cars have built-in navigation systems that can display the angle of the car on a route. There are also smartphone apps and GPS devices that can provide this information. Additionally, there are online calculators and software programs specifically designed for this purpose.

Similar threads

  • Introductory Physics Homework Help
Replies
6
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
1K
Replies
5
Views
992
Replies
2
Views
4K
  • Mechanics
Replies
6
Views
1K
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
5
Views
1K
Replies
15
Views
3K
Back
Top