# Circle in 3D

## Recommended Posts

Hi, I usually draw circles in 3D using the following formula: point = (center.x + (radius * cos(a)), center.y + (radius * sin(a)), center.z) Not the most efficient way considering the cos and sin but performance is not my primary concern here. The problem with this is that the circle is always draw along 2 axis (in that case X and Y). What if I want to draw a circle on any plane in 3D space, given 3 points on that plane (I have 3 points on the circle as well as its center, I'm just missing the formula to render it on the screen). Thanks for your help!

##### Share on other sites
3 points + centre is overkill (a plane is defined by three points).

Say, a centre and two points :) these points create a frame that you can use to orientate your circle.

Quote:
 // three vector (right, up, dir) for a orthormal frame.// each vector will be of unit length, and perpendicular to each other.// they form an orientation matrix, or a othonormal coordinate system.Vector right = (a - centre);Vector dir = (b - centre);Vector up;right = (a - centre);dir = (b - centre);up = dir.cross_product(right);up.normalise();right.normalise();dir = right.cross_product(up);

from then on, you can do...

Quote:
 float a = 0.0f;const int slices = 32;float da = two_pi() / slices;for(int i = 0; i < slices; i++, a+= da){ point = centre + (right * (cos(a) * radius)) + (dir * (sin(a) * radius));}

Normal of circle will be 'up'. 'right' is, if you will, the x-axis of your circle, and 'dir' will be the 'y' axis of your circle.

##### Share on other sites

Thanks! It's working great :D

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628337
• Total Posts
2982164

• 9
• 24
• 9
• 9
• 13