Jump to content
  • Advertisement
Sign in to follow this  

How to draw a circle given three points in 3D space

This topic is 3876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, guys, Here are three points, not in one line, with x,y,z value. I want to draw a circle through these three points with OpenGL. I know how to draw it in 2D plane, but I am blocked in 3D space. I need your help. How to fix its circle center position, and radius. Thanks!

Share this post

Link to post
Share on other sites
The method for 3d is almost identical to 2d, but there's a "complication".

In 3d there isn't just 1 perpendicular bisector of a line, there are an infinite number, so you need to narrow it down.

The points (lets call them ABC) define a plane, your circle will lie in this plane.
You can get the normal to the plane using the cross product of any 2 pairs of points.
n = AB x AC

The bisectors you need, will also lie in the plane, so they will be perpendicular to both the original line (AB or whatever) and the plane normal.

So you can find their directions using the cross product as well.
BisectDir(AB) = AB x n
BisectDir(AC) = AC x n

From there it's the same as 2d.
Find where the Bisectors meet... that's your centre, and from there radius is easy.

Share this post

Link to post
Share on other sites

If the Center is C, and the three points are P1, P2, P3. Then we could create three equations.

|| P1 - C || = || P2 - C ||
|| P1 - C || = || P3 - C ||
(( P2 - P1) x ( P3 - P1)) . ( C - P1) = 0

According to these three equations, I think I can got the circle center position.
But it force me the resolve the linear equation and seems complex.

Hmm... I suddenly got an idea I can avoid resolving the linear equation.

Center: C
Three points: P1, P2 ,P3

First, I can use the Heron's formula to get the excircle radius (exRadius):
2 * Area
c - a + b

Then the length of Bisector C to P1 P2 (lenBisector) is:
sqrt( exRadius * exRadius - || (P1 - P2) / 2 || * || (P1 - P2) / 2 ||

Then norm this length to Bisector.
Bisector = lenBisector* normalize((P1 - P2) x n)
The 'n' is the normal of the triangle plane.

Then, the center of the circle is

C = (P1 + P2 ) / 2 + Bisector


,' `.
,' `.
,' `.
,' `.
,' `.
,' `.
,' `.
,' C(enter) `.
,' ._ `.
,' | ``-.._ `.
,' Bisector| `-.._ `.
,' | `--._ `.
P1 P2

Share this post

Link to post
Share on other sites
Seems OK...

[edit]I Thought I remembered what Heron's was.. but didn't.

But Heron's Formula isn't what you want...
Heron's calculates the area from the lengths of the sides...
It doesn't get you the exRadius.

What you need is
exR = abc / (4 * Area) = abc / (2 * |(p1-p2)x(p2-p3)|)

Though bare in mind, there are 2 solutions to the math...
One on either side of the line P1-P2

You'll need to check that the point you calculate (C) actually IS exRadius from P3..
and if not.. reverse the direction of the Bisector vector.

The beauty of the "standard" methods, and the reason they are slightly more complex, is that they result in only a single solution.

But since we're "coding" here, and can perform an IF....

However, you might find that one of the "standard" methods is actually faster.
Whilst they may seem quite complex, the final computation is relatively simple, (mostly Adds Subs and Mults... 1 DIV, 1 SQRT)
Whereas your method looks like it's got about 5 SQRTs.
Not a big problem, unless speed is critical to you.

[Edited by - daftasbrush on April 3, 2008 5:27:27 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!