I am trying to implement the pen tool from Adobe Illustrator in OpenGL. I am trying to get the coordinates of the reverse tangent upon mouse release. I tried negating the coordinates I got upon mouse release but that doesn't seem to work.

enter image description here

void myMouse(int button, int state, int x, int y) {

int DirectionHandleX;
int DirectionHandleY;

// If left button was clicked
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) 
    drawDot(x, SCREEN_HEIGHT - y);
else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) 
    DirectionHandleX = x;
    DirectionHandleY = y;
    drawDot(DirectionHandleX, SCREEN_HEIGHT - DirectionHandleY);

2 Answers 2


Assuming you're doing spline curves: Let p be the point at the end of your curve (the one marked with a solid square above). Let h be your handle point (the one denoted as such). The vector from p to h is (h-p). To get the other handle point, take p + -(h-p). This can be more concisely written 2p-h.

  • $\begingroup$ So do I do the calculation for the x and y variables since I'm using a set of two separate integers? New to graphics programming and bad at math haha! $\endgroup$ Commented May 8, 2022 at 0:23
  • 1
    $\begingroup$ Correct... if you have x & y coordinates (integer or floating point; doesn't matter), you do the math separately. Ex: To get v=h-p: vx = hx-py; vy=hy-py. $\endgroup$
    – jh100
    Commented May 8, 2022 at 1:03

One way to approach this topic that can help is to distinguish between points and vectors as distinct types and make sure your operations fit into one of the "known good" scenarios:

  1. Point + Vector = Point
  2. Point - Vector = Point
  3. Point - Point = Vector
  4. Point + Point = total nonsense
  5. Scalar * Vector = Vector
    eg. -1 * Vector = -Vector, the reverse direction
  6. Scalar * Point = total nonsense
    eg. -1 * Point = a conceptual mistake, you can reverse a vector but not a point

You can think of this as the points are the real dots on the screen and vectors are just invisible arrows. You can only get a point from a vector if you attach it (ie. add it) to another point.

You can also kind of think of this as the points are unsigned quantities and the vectors are signed quantities. The points have only position, whereas the vectors have only direction -- even though they can have the exact same representation in the computer. You could enforce the distinction to some degree by using integers for points and floating point for vector components. This also emphasizes the scalability of vectors, a feature that points lack.

Aside: a more apt analogy in programming might be to consider points as *pointers and vectors as ptrdiff_ts. But those would be a bad choice of types for implementing these objects for graphics.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.