Calculating rotation along a path

前端 未结 6 432
暖寄归人
暖寄归人 2021-01-03 09:52

I am trying to animate an object, let\'s say its a car. I want it go from point

x1,y1,z1

to point x2,y2,z2 . It moves to those points, but

6条回答
  •  醉话见心
    2021-01-03 10:32

    In general terms, the direction the car is pointing is along its velocity vector, which is the first derivative of its position vector.

    For example, if the car is going in a circle (of radius r) around the origin every n seconds then the x component of the car's position is given by:

    x = r.sin(2πt/n)
    

    and the x component of its velocity vector will be:

    vx = dx/dt = r.(2π/n)cos(2πt/n) 
    

    Do this for all of the x, y and z components, normalize the resulting vector and you have your direction.

提交回复
热议问题