views:

299

answers:

2

Hello:

I wish to determine if a Point P(x,y,z) is inside a 2D circle in 3D space defined by its center C (cx, cy, cz), radius R, and normal to the plane the circle lies on N.

I know that a point P lying on a 2D circle in 3D space is defined by:

P = R*cos(t)*U + R*sin(t)*( N x U ) + C

where U is a unit vector from the center of the circle to any point on the circle. But given a point Q, how do I know if Q is on or inside the circle? What is the appropriate parameter t to choose? And which coordinates do I compare the point Q to see if they are within the circle?

Thanks.

+3  A: 

I'd do this by breaking it into two parts:

  1. Find out if the point is on the same plane as the circle (ie. see if the dot product of the vector going from the center to the point and the normal is zero)

  2. Find out if it's inside the sphere containing the circle (ie. see if the distance from the center to the point is smaller than the radius).

tloflin
+9  A: 

Project P onto the plane containing the circle, call that P'. P will be in the circle if and only if |P - P'| = 0 and |P - C| < R.

andand
and if I wish to include the boundary of the point in my check, do I check |P-C|<=R and |P-P'|=0?
Myx
http://en.wikipedia.org/wiki/3D_projection
HyperCas
Presumably all your coordinates are floating-point numbers, which means you should be careful when doing things like "|P - P'| = 0". It will rarely come out to EXACTLY zero, so you can do something like "|P - P'| < e" where e is some very very small number.
MatrixFrog
@Myx, Yes, and the point that MatrixFrog makes is also very salient for actual implementation. Also, tloflin's thought of checking <P-C, N> = 0 (or within some suitably small range about 0) instead is probably a better choice (easier to compute) than my suggestion of projecting P onto the nearest point P' in the plane containing the circle.
andand
Thanks for the tips. For me, I already had a Project function implemented so it didn't matter to me which one I used (Project or Dot product with Normal).
Myx