View Full Version : Draw an Arc between two points (AC) for an angle (A-B-C) in 3d space

jamie_wizard

08-04-2012, 06:08 AM

Hi everyone, I'm working with OpenGL and I need to be able to draw angle measurements between any three points in 3d space. I have written code for calculating angles between three points in 3d space (i.e. 3 atoms), however I need to be able to draw an angle to depict this.

www.al-nasir.com/www/Jamie/WebTmp/ArcProblem.jpg

The arc has to be drawn in line with the flat plane between the three 3d points (the plane that is between A B and C) and not veer to either side of this plane.

I've been racking my brain out to no avail. I've some code to draw the arc but its a bit messy and although the arc is nicely drawn it is not inline with the plane.

Would be most grateful for a solution to the problem!

Darth_Malloc

08-07-2012, 07:26 PM

Hi jamie_wizard,

I am new to OpenGL myself, but I will do my best.

I think that what you want to try to do first is establish two points on the lines of the plane, so that each point is on the midpoint of the corresponding line. When you draw the polygon that forms the arc, make sure it runs through those two points, and does not exceed the vertex of the plane. That way, the arc will be tangent to both lines of the plane, and will not exceed the boundaries of the plane.

Hope that helps.

Best of luck.

Carmine

08-08-2012, 10:01 AM

It can all be done with simple vector operations.

First translate your 3 points to the origin by subtracting the vector A from each point.

This will give you D' = D - A, E' = E - A, and A' which is at the origin.

The plane containing the points A', D', and E' is defined by its normal vector N.

Vector N is simply D' x E' (i.e. the vector cross product of D' and E').

You will also need to find the angle (theta) between D' and E'.

Now select a point somewhere on D', call it B. It could be D' normalized.

Points making up an arc from D' to E' are simply vector B rotated around N.

To get an arc made up of 10 points, divide theta by 10.

Rotate B around N by 10*i, which i steps from 1 to 10.

So you'll need a generic rotation routine which can rotate a vector around another vector.

These can be found on the Internet if you don't have one already.

All of the above will create an arc from D' to E'.

Since you want an arc from D to E, you must translate the D'E' arc by A.

So you need routines to do vector addition, subtraction, cross product, and

generic rotation (rotation around a vector which is not the X, Y, or Z axis).

Good luck.

jamie_wizard

08-09-2012, 08:18 AM

@ Darth_Malloc: Thank you for your attempt to try and answer my Question. I understood your logic but not quite sure how to constrain the arc to the vertex, which I think Carmine has answered below. Eventually I managed to draw an approximate arc using a bezier but its not perfectly round. Thanks again.

@ Carmine: Thanks for your very rational step by step guide. I've used a bezier solution but its not a perfect arc so I will give your suggestions a go!

I have looked up and coded functions for the common operations vector addition, subtraction, cross product etc.. but will search to find out how to rotate around a vector - should be do-able!!

Thanks again :-)

jamie_wizard

08-14-2012, 06:18 AM

Thanks Carmine for your answer and logical steps. I've solved the problem using a 3d bezier curve although it doesn't give a perfect arc so I will try your method out. I have coded functions for common vector ops such as cross product, dot product etc.. but will look for some info on rotation about a vector.

jamie_wizard

08-14-2012, 06:20 AM

Thanks Darth_Malloc, I understood your logic which re-iterates what I wanted but think Carmine has given a good answer below!

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.