Grasshopper

algorithmic modeling for Rhino

What's the best way to test whether or not a point lies on a ray defined by two points?

Views: 1737

Replies to This Discussion

This is my workaround:

I guess it's not bad but I think there must be a better way.

Let me know if anyone has a cleaner solution, I'd love to find a more "legit" way.

Attachments:

 

How about using Plane CP (find the foot of perpendicular) instead of Plane X Line..

 

Attachments:

If the ray is finite, then just use Curve CP and test whether the distance from the point to the curve is less than, say, 1e-12 or whatever tolerance you're happy with. Never use a distance of zero because chances are there will be some noise in the least significant digits.

If the ray is semi-finite or infinite the answer gets more complex, is this the case?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

what about the dot product of the ray vector and the vector from the ray start to the point in question, with both vectors unitized? It will be 1.0 if the point is in the ray and something else in all other situations, I think. 

That's pretty clean comparitively.

I meant to reply to David but the device I was using died mid-response.

I actually did reply but it was confusing so I deleted it.

Anyways what I realize is I should not have asked to test a point on a ray, but instead an infinite line. Not a curve (and I guess technically not a ray).

But, it looks like both of our methods work as far as I can tell. I might have to adopt yours since it shaves a few components off of mine.

thanks,

-Brian

actually will yours work for an infinite line as opposed to one with an origin point? I'm not too familiar with using vector multiplications. 

This is obviously my mistake since I wasn't clear about what I actually needed (line vs. ray intersection).

I think that what your question reduces to is will Andrew's definition work if the points on the infinite line are arbitrarily chosen with respect to the test point.  In that case I think you would need to consider the case where the direction of one vector is 180 degrees out of phase with the other ie. its along the same direction but with opposite sense.  In other words you must test for -1 as well as 1.  Using a(dot)b=|a|*|b|*cos(theta)  if vectors a and b are each unitized (each equal to 1) then the dot product returns the cosine of the angle between them.  If this is either 1 or -1 (cos(0) or cos(180)) then those vectors are at least parallel and if they have one common point then they are on the same line.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service