View Full Version : find out if a point is on a curve
Hello!
Is there a way to know if a certain point is located on a curve?
I have several straight nurbsCurves on stage, and one nurbs surface which has one side over one of these curves. I need to find out on which curve the surface is over... the idea was to check each vertex of the surface and check if it is located on a curve, using MEL to automate it.
The image shows more or less the situation....
http://nier.com.br/arquivos/temp/cgTalkDoubt.png
Any ideas? I'm kinda lost...
Thank you!!
Daniel


grantimus
06252007, 09:34 PM
Well as you've probably found out by now, there is no command in MEL to test whether or not a point lies on a curve. But there is some math you can do to test this. The math for curved lines can get a little hairy, so what I'm about to outline for you will only work on straight curves. Since that is what you're dealing with, I hope you won't mind :)
First you need to get the positions of the curve's endpoints. There are a lot of ways you can go about doing this, I like the xform command.
float $endPoint1[] = `xform q ws t yourCurve.ep[index of first endpoint]`;
float $endPoint2[] = `xform q ws t yourCurve.ep[index of second endpoint]`;
Next you'll want to assign the position of the point you want to test to a float array.
float $testPoint[] = {x value, y value, z value};
Now you'll want to define two vectors. You'll be doing some math on these vectors to determine if the point lies on the curve or not. The first vector is defined by the position of the two endpoints. The second vector is defined by the position of the test point and the position of one of the end points (I'll use the second endpoint).
vector $vector1 = <<$endPoint1[0]  $endPoint2[0],$endPoint1[1]  $endPoint2[1],$endPoint1[2]  $endPoint2[2]>>;
vector $vector2 = <<$testPoint[0]  $endPoint2[0],$testPoint[0]  $endPoint2[0],$testPoint[0]  $endPoint2[0]>>;
Now that you have the two vectors defined, find the angle between the two.
float $angle = angle($vector1,$vector2);
If the angle between the two vectors is greater than zero, the point does not lie on the curve. However, if the angle is zero you still can't be absolutely certain that the point lies on the curve. You need to perform one last test, for this test you need to get the length/magnitude of the two vectors.
float $mag1 = mag($vector1);
float $mag2 = mag($vector2);
I $mag2 is less than or equal to $mag1,you know for certain that the test point lies on the curve.
hey!
Thanks a lot! I was thinking that I would have to recur to math to do it... And yes, I'll deal only with straight lines, so your outline seems perfect....
I'll give it a try and the I'll post the results here...
Thanks!
Daniel
CGTalk Moderation
06252007, 09:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.