# Finding the angle of a line given 2 other lines

I'm trying to implement some 2D vehicle physics. For this to work I have 2 wheels attached to the body of the car. After doing some collisions checks I place the wheels at their new position. Say the first wheel is at (-0.5, 1) and the second wheel is at (0.5, 1) I now have to calculate the angle and position of the body between the wheels. In the given example the angle should be 0. But how do I calculate the angle?

Because pictures make everything easier: The blue lines are the positions of the wheels and the pink line is the body. Given the two positions of the wheels, at what angle is the body in relation to the ground?

• I don't understand the image. Is this top-down view? Why is the wheel on the right larger than the one on the left? – bummzack Dec 15 '11 at 10:58
• Hmm, yes the image isn't too clear, sorry. But I meant the blue lines to be vectors from Y=0 to indicate the position – Roy T. Dec 15 '11 at 11:02
• Oh I see. So the pink line is the wheels axis? – bummzack Dec 15 '11 at 11:06
• Yeah exactly that – Roy T. Dec 15 '11 at 11:28

angle = atan2(frontwheel.y - rearwheel.y, frontwheel.x - rearwheel.x);