<p>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.</p>

CC BY-SA 4.0
2022-05-08T00:23:07.077Z
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!
Arjan Singh
CC BY-SA 4.0
2022-05-08T01:03:11.630Z
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.
jh100
CC BY-SA 4.0
2022-05-08T00:10:37.703Z
2022-05-08T00:10:37.703Z
jh100
<p>One way to approach this topic that can help is to distinguish between points and vectors as distinct <em>types</em> and make sure your operations fit into one of the &quot;known good&quot; scenarios:</p>
<ol>
<li>Point + Vector = Point</li>
<li>Point - Vector = Point</li>
<li>Point - Point = Vector</li>
<li>Point + Point = total nonsense</li>
<li>Scalar * Vector = Vector<br />
eg. <em>-1</em> * Vector = -Vector, the reverse direction</li>
<li>Scalar * Point = total nonsense<br />
eg. <em>-1</em> * Point = a conceptual mistake, you can reverse a vector but not a point</li>
</ol>
<p>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. <em>add</em> it) to another point.</p>
<p>You can also kind of think of this as the points are <em>unsigned</em> quantities and the vectors are <em>signed</em> 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.</p>
<p>Aside: a more apt analogy in programming might be to consider points as <em><code>*</code>pointers</em> and vectors as <em><code>ptrdiff_t</code>s</em>. But those would be a bad choice of types for implementing these objects for graphics.</p>

CC BY-SA 4.0
2022-05-09T00:46:10.410Z
2022-05-09T19:23:25.227Z
2022-05-09T19:23:25.227Z
luser droog
<p>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.</p>
<p><a href="https://i.sstatic.net/hO0lg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hO0lg.png" alt="enter image description here" /></a></p>
<pre><code>void myMouse(int button, int state, int x, int y) {

int DirectionHandleX;
int DirectionHandleY;

// If left button was clicked
if (button == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN) 
{
    drawDot(x, SCREEN_HEIGHT - y);
}
else if (button == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_UP) 
{
    DirectionHandleX = x;
    DirectionHandleY = y;
    drawDot(DirectionHandleX, SCREEN_HEIGHT - DirectionHandleY);
}
</code></pre>

<opengl><bezier-curve><point>
How to get coordinates of opposite direction from mouse release point relative to a point?
Arjan Singh
# How to get coordinates of opposite direction from mouse release point relative to a point?

(Asked by: username_0 on 2022-05-07)

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](https://i.sstatic.net/hO0lg.png)](https://i.sstatic.net/hO0lg.png)

```
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);
}

```

**Tags:** opengl, bezier-curve, point


---

## 2 answers

### Answer by username_1 on 2022-05-08. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: 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!  
> **username_1**: 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.  

---

### Answer by username_2 on 2022-05-09. Score: 1

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_t`s*. But those would be a bad choice of types for implementing these objects for graphics.


---

