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.