Thread: Drawing tangents for a bezier curve in OpenGL

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    12

    Drawing tangents for a bezier curve in OpenGL

    I'm currently trying to draw a bezier curve using 4 control points. I'm currently drawing the curve using the cubic equation in a for loop where my t value increments by 0.1 each time:

    Code:
        for (double t = 0; t < 1; t += 0.1){
            float Px =(pow((1 - t), 3) * cam_pos_points[0].positionx()) + 
                ((pow((1 - t), 2) * t) * cam_pos_points[1].positionx()) + 
                (((1 - t) * pow(t, 2)) * cam_pos_points[2].positionx()) + 
                (pow(t, 3) * cam_pos_points[3].positionx());
            float Py =(pow((1 - t), 3) * cam_pos_points[0].positiony()) + 
                ((pow((1 - t), 2) * t) * cam_pos_points[1].positiony()) + 
                (((1 - t) * pow(t, 2)) * cam_pos_points[2].positiony()) + 
                (pow(t, 3) * cam_pos_points[3].positiony());
        }
    And I've set up my control points like this:
    Code:
    std::vector<ControlPoint> cam_pos_points;
        cam_pos_points.push_back(ControlPoint(-0.79, 0.09, 0.2, 0));
        cam_pos_points.push_back(ControlPoint(-0.88, -0.71, 0.2, 1));
        cam_pos_points.push_back(ControlPoint(1.3, -0.8, 0.2, 2));
        cam_pos_points.push_back(ControlPoint(0.71, 0.76, 0.2, 3));
    So putting these 4 control points into the above equation gives me more points which form the bezier curve. I've also set up a way to move these points which will modify the curve. The way I set that was whenever I clicked on a point, after I let go of the mouse, the new position of the point would be the mouse position and then I re-calculate the curve based on the new position of this point.

    Now I'm trying to draw the tangents for each point on the curve. The problem is I have no idea what calculations I have to do to calculation the tangent and make the angle of the curve based on the tangent position. To modify the tangents I would simply re-calculate the angle of the curve based on the new position of the tangent but I don't know what the initial calculations are for the tangents.
    Last edited by Salem; 06-12-2017 at 05:10 AM. Reason: line wrapped for readability

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. drawing my ui (openGL)
    By hannibar in forum Game Programming
    Replies: 1
    Last Post: 04-12-2006, 07:24 AM
  2. Curve drawing in C
    By Brokn in forum C Programming
    Replies: 3
    Last Post: 12-14-2005, 01:59 AM
  3. Bezier curve
    By simo in forum Windows Programming
    Replies: 2
    Last Post: 12-11-2005, 03:01 AM
  4. Attaching Cylinder to Bezier curve...
    By MipZhaP in forum Game Programming
    Replies: 5
    Last Post: 09-02-2004, 10:09 AM
  5. Moderators tangents
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 02-28-2002, 07:55 AM

Tags for this Thread