tags:

views:

982

answers:

8

I have two 2d circles in 3d space (defined by a center, normal, and radius) and I'm trying to come up with a pair of points that is one of the set of closest pairs of points. I know that there are anywhere from 1 to an infinite number of point pairs, I just need a single matching pair.

Is there a simple way to do that? Precision is not essential. The radius of both circles are the same, non-zero value.

In case the background is helpful, my overall algorithm takes in a NURBS curve in space and extrudes a 2d polygon along the curve, yielding a deformed cylinder. I just sample several points along the curve. The normal of each circle is the NURBS curve tangent, and I'm trying to figure out how to align adjacent samples, so I don't get weird twisting. It seems that the closest points on adjacent samples should be aligned.


Thanks for all the responses here.. this part of the project got a little delayed, which is why I haven't tested all the answers yet. I'll be sure to toss up some images here and mark an answer when I get to work on this again.

A: 

Isn't this just a matter of constructing the line between the two centers of the circles/spheres and finding the intersection of the line and the circles? The solutions that are closest are it (unless the circle intersect, then the answer depends on how you want to interpret that case).

plinth
They're 2 circle on different 2D planes in 3D space, if I read the question correctly. If they were spheres, or 2 circles on the same plane your answer would be correct.
patros
+1  A: 

Yikes, unless the circles happen to be on the same plane or parallel planes I think the only way to do it is to find a minimum on the equation of the distance between two points on the circle.

http://www.physicsforums.com/showthread.php?t=123168

That link shows how to get the equation of each circle in 3D space, then minimize for the distance formula between those equations. Not pretty though, hopefully someone will come up with something more clever.

patros
+1  A: 

For what you describe, it is sufficient to select a point on the perimeter of the first circle and find the point on the perimeter of each circle along that is closest to the one selected for the previous circle; this will completely constrain the polygonization, with no twisting, and should be much easier to solve than the general case - simply find the point on the plane containing the second circle that is closest to that selected in the first, and intersect the line passing through that point and the second circle's center with the second circle's perimeter.

However, this might not yield as pleasing a polygonisation for the extruded cylinder as keeping the polygon area constant as possible, and to do that will require some twisting between adjacent circles.

moonshadow
A: 

Project the circles on all the three planes XY,YZ,ZX.
Projections will be ellipses.
Find 3 pairs of the closest points on each of the three planes.

Then we obtain table something like

    Circle1 Circle2
XY    p1      q1
YZ    p2      q2
ZX    p3      q3

Still struggling with the solution. :D Please help everybody.

TheMachineCharmer
+4  A: 

What you are really trying to compute is the pair of points that minimizes the distance between points that lie on 2 different circles in 3 dimensions. The method that you should be employing to find the exact solution (as in almost all optimization problems) is to represent the distance as a function of all possible points and to take its derivate with respect to the independent variables and set the resulting expressions to 0. Since you have 2 circles, you will have 2 independent variables (ie. the angle of a point on one circle and one on the other circle). Once you have solved the minimization equations you would have also found the points on the circles that will satisfy your constraint. (Basically you will find the angles on the circles for the pair of points you are looking for.)

I have found a paper online (at this site) that rigorously goes through with the calculations but the end result is solving an 8th order polynomial equation. You might try to simplify the equations and come up with a less exact solution that satisfies your needs.

There is also an paper that claims to have a much faster algorithm for finding the distance between two circles in 3d; however, I cannot view the contents and, thus, cannot tell if it also gives you the pair of points that satisfy that condition.

UPDATE: Having re-read your question, I see that even though you are asking for a way to find the closest pair of points on two circles in 3 dimensions, I think, you should pay more attention to the properties of the NURBS curve that you are trying to extrude the 2D polygon along. You mention that the orientation of the circle at a given point on the curve is specified by the tangent vector at that point. However, there is more to 3D curves than just the tangent vector; there is the normal (or curvature) vector that points towards the center of curvature of the curve at a given point and then there is the torsion vector that basically specifies the amount of "lift" of the curve from the plane given by the tangent and the normal vectors. All of these define a (what is called) Frenet frame. You can read up more on these at the Wikipedia article.

My suspicion is that you can achieve the effect you desire by joining the points of consecutive circles that each lie along the the normal vector direction of the underlying 3D curve. That way, you will have twisting only when the curve is actually twisting, ie when the torsion vector is non-zero and the normal vector is changing direction as well. In other circumstances, this should satisfy your actual need.

You probably don't need the overkill of finding closest points on consecutive circles.

paracycle
I haven't looked at it, but this site says it has c++ source for the algorithm in the second paper you mentioned: http://jgt.akpeters.com/papers/Vranek02/
Anton Geraschenko
My first attempt at a solution was using Frenet frames, which led to bad results, I think when the curve has an inflection point. I'll try to get a screenshot up here shortly.
tfinniga
Himm, I see. It would be great if you can post the curve function, the point for which you get a bad result and the relevant screenshot. I would be interested to see what is going wrong.
paracycle
+1  A: 

I think with the two closest points you might still get weird twisting... An extreme example: Let's assume both circles have the R=1. If the first circle's centre is O, and it is sitting on X-Y plane, and the second circle's centre is sitting at X=1,Y=0,Z=0.01, and it just slightly tilted in the growing direction of X, the closest points on the two circles will for sure get the "weird twist" you are trying to avoid. Since the closest points would not get you the weird twist in case the second circle is at X=0,Y=0,Z=0.01 and is equally tilted, then at some point the statements "aligned to two closest points on two circles" and "no weird twisting seen" no longer correspond to each other.

Assuming this can happen within the constraint of NURBS, here's another idea. In the start, take the three points on the NURBS curve - two that belong to the centers of your circles, and the third one precisely inbetween. Draw a plane between the three. This plane will cross the two circles at 4 points. Two of these points will be on the same "side" of the line that connects the centers of the circles - they are your alignment points.

For the next alignment points you would take the alignment point of the "previous circle", and draw the plane between the center of the "previous circle", this alignment point, and the center of the "new circle". From this you get the "next alignment point" based on the intersection with the other circle.

Next step - "previous circle" = "new circle", and the "new circle" - your next one according to the NURBS curve.

If the radii from the centers of the circles to the selected alignment points cross, you know you the picture will look a bit ugly - that's the scenario where with the "closest point" algorithm you'd still get the weird twisting.

I think the coordinates of the point on the circle that is intersection with the plane going via its center should be easy to calculate (it's a point on the line made by intersection of the two planes, one of the circle and the target plane; at the distance R from the center).

I don't have the rigorous proof to fully assert or deny the above - but hopefully it helps at all, and I think it should be quick enough to verify, compared to calculating the closet points on the two circles... (If there are any flaws in my logic, the corrections in the comments are very welcome).

Andrew Y
Good point, I'll have to check my assumptions.I think for piping a curve, there's got to be some kind of constraint between minimum radius of curvature and radius of the pipe. I'm still trying to visualize what's going on with the example you posted, but it seems related. The twisting I'm worried about is twisting about the tangent..
tfinniga
Yes, I think this constraint could be checked by applying the step similar to the first one, on a sufficiently small piece of the curve - then if the radii of the circles intersect (when drawn on the plane connecting the three subsequent points on the curve), then the circles are too big for this curvature.
Andrew Y
+1  A: 

Extend the circles to planes (using the center points and normals). If the planes are parallel, then any points will do. If the planes are not parallel, then they intersect in a line. Construct the plane through the two centers of the circles perpendicular to the line. The two circles intersect this new plane in four points. These four points are the two nearest points and the two farthest points on the circles.

Ned Batchelder
" If the planes are parallel, then any points will do." Is this true? Shouldn't you take in this case a plane through the two centers perpendicular to the circles' planes?
balint.miklos
-1 Sorry, this answer is completely wrong. If the planes are parallel, any two points **won't** do; to see that, just consider the case where the circles are in the *same* plane. The other part is also wrong. Imagine slicing a sphere with two planes (neither of them passing through the center of the sphere). This cuts out two circles on the surface of the sphere. Do this in such a way that the circles actually intersect (ie the line of intersection between the planes passes through the sphere). The distance between the circles is zero, but this answer says it's strictly positive.
Anton Geraschenko
There may not even exist a plane that is perpendicular to the line of intersection **and** passes through both of the centers of the circles.
Anton Geraschenko
+1  A: 

The thread here, mentioned in another answer gives the parameterization formula for a 3D circle: P = R cos(t) u + R sin(t) nxu + c, where u is a unit vector from the centre of the circle to any point on the circumference; R is the radius; n is a unit vector perpendicular to the plane and c is the centre of the circle, t goes from 0 to 2pi, and by nxu I mean "n cross u". Parameterize one circle this way, and another similarly with a different parameter, say s. Then each point Pt on the first circle will have coordinates in the variable t, and each point Ps on the second circle will have coordinates in the variable s.

Write the distance function d(s,t) between Ps and Pt in the usual way (or better, the square of the Euclidean distance so you don't have to mess with the square root when you take derivatives). The graph of this function d of two variables is a surface over a 2pi by 2pi square in the s,t plane, and it's minimum is what you're after. You can determine it with the standard calculus methods, e.g. as explained here.

Glenn