Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Rotating a body in the direction of its trajectory

  1. #1
    Newbie Newbie
    Join Date
    Nov 2014

    Rotating a body in the direction of its trajectory


    I am writing a rocket simulator and I am moving the rocket along a trajectory.
    I would like the rocket to point in the direction of the tangent to the trajectory.

    The trajectory happens to be such that Y(t) is a parabola and X(t), Z(t) are linear, but I would like this to work for any trajectory in 3D space.

    I tried using the glRotate function with angles I calculated from the slopes of x(t), y(t), z(t).
    For instance, the slope of Y(X) can be calculated using the arctan of dy/dt divided by dx/dt.
    This worked for some trajectories but not for all.

    I have seen a few solutions that seem to involve a lot of calculations, but intuitively I assume that there must be a simple solution I am missing.

    For instance, as I know where the rocket is at T and at T + dT, can I not just rotate the rocket so that it points from:
    {x(t), y(t), z(t)} to {x(t+dt), y(t+dt), z(t+dt)} ?

    Thanks for any tips on how to do this


  2. #2
    Member Regular Contributor
    Join Date
    Apr 2012
    Los Angeles
    Assume rocket is modeled with X axis through the nose, and you want Z to be in the orbit plane as the rocket propagates.
    So with no rotations, the rocket lies in the horizontal plane pointed eastward.
    Code something similar to below works for me.
    You may have to make minor adustments like adding a '-' sign, adding 90.0 degs, etc.
    If the rocket isn't modeled as above, put in some rotations just above the Draw_Rocket call to orient it properly.
    This is all there is to it. Note that rockets usually deviate from this attitude a bit (angle of attack).
    Code :
        dx = x(t+dt) - x(t);
        dy = y(t+dt) - y(t);
        dz = z(t+dt) - z(t);
        dq = sqrt (dx*dx + dy*dy);
        az = atan (dy/dx);
        el = atan (dz/dq);
           glRotate (az, 0,0,1);   // Azimuth
           glRotate (el, 0,1,0);   // Flight path angle.
           Draw_Rocket ();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts