# Drawing a quadratic curve and an arrow with OpenGL (JOGL)

Hello to all OpenGL-ers,

I am a complete beginner to OpenGL or to any graphics programming whatsoever, and as such I need some help…

I am drawing a quadratic curve that connects two shapes, as shown in the picture below: The curve connecting the two shapes is quadratic, drawn with the following JOGL code:

``````
// Draw quad curve between two points (x1, y1) and (x2, y2).

double x0, y0; // Predefined curve control point
double angle;  // Pre-calculated angle of rotation
double a = -y0 / (x0 * x0);

gl.glPushMatrix();
gl.glTranslated(x1, y1, 0);
gl.glRotated(Math.toDegrees(angle), 0, 0, 1);

// Draw curve
gl.glBegin(GL.GL_LINE_STRIP);

double x, y;
for (x = 0; x < d; x += 1) {
y = a * (x - x0) * (x - x0) + y0; // Quad curve
gl.glVertex2d(x, y);
}

gl.glEnd();
gl.glPopMatrix();

``````

The two points (x1, y1) and (x2, y2) are the two centers of the shapes 1 and 2 of the figure. What I want to do now is draw an arrow at the point where the curve meets the square, i.e. I want to draw this curve to represent a directed edge, if this was a graph. The two shapes are drawn independently in another location in my source code.

However I feel that I am doing/thinking this wrong, since I am unable to find a way to draw the arrow. I have tried calculating the distance of each point of the curve (as I draw it) from the center of the square (including the distance of the border of the square) and then keeping the last point that touches the square’s border, but this gets messed up because of all the transformations, since the square is drawn without any transformations.

What am I doing wrong? Please ask if something is not clear enough!

Always remember OpenGL only draws graphics it does not solve logic problems like where a square intersects a curved line. That is your problem - there is no shortcut sorry.

Hmmm this is what I was worried about. If I look at this from a different view, I would be able to solve my problem if there was a way to maintain all points of the curve (before they are transformed) in an array, and after the matrix is popped, to apply the transformation to the point coordinates themselves. Would this be possible with OpenGL transformations?