Sign in to follow this  

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 this post

Link to post
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.


// 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);

dir = right.cross_product(up);

from then on, you can do...


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 this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this