Grasshopper

algorithmic modeling for Rhino

Hi! I try to check two lines whether they parallel or not. The first idea that comes into my head was check their intersection, but as you can see there when the lines slightly not parallels each other, there is two different point of intersection. Maybe i can use the fact that the points are different as the added condition, but how predictable this way is? Or maybe do you know better idea?

And by the way maybe they are parallel, i don't know because as figure out they have different length.

bug2.gh

Views: 5998

Replies to This Discussion

Absolute values of the unitized vector do not work, since it could also be a mirrored version. So this one is a little longer...Best, p

It's easier to cast the lines to vectors, then use Vector Angle and compare to a threshold angle:

Attachments:

How do you deal with parallel lines running in opposite directions?

Thank you very much, Phillip! Your definition works pretty good, though with this approach would be bit difficult to get the boolean answer. Much more important that i'm not clearly understanding how it's works :)

And thank for David Rutten, it's so obviously but i forgot about it :)

By the way in this particular case i always know the direction of the lines

Another simple option could be to check if the length of the cross product is less than some value. This will be zero if the lines have the same or opposite directions.

It's amazing how simple can become a method, using just 2 components to achieve a complete new function!

Before reading here I neither know what vector cross product was...

gj

Wow - that's weird that Cross Product takes lines as inputs!  Looks like it normalizes them into vectors also.  Whoda thunk?  There's nothing in the docs to say that - at least not in the docs for cross product.  Is there some general principle in GH where lines are normally accepted in place of vectors?  I tried passing a curve with three control points into cross product and it seems to convert that into the vector (0, 0, -1) which is kind of odd.  You'd think they'd just reject it as bad input.

Vector Angle goes up to pi radians/180 degrees. So it'll give different angles for parallel and anti-parallel vectors. If you also want to find anti-parallel lines, then you should compare the angles to be [< t] OR [> (pi-t)]

if it is just about two lines that should be compared, why not simply reverse one of the vectors and check if they are parallel at the same time? if one of the two evaluations is true, they are parallel

Because usually in here less [components, data, computation time, obviousness,...] is more. In this sense most of the versions are more or less equal..., but the winner is still Daniel. 

I´ll get some coffee.

Without angle measurement (not really sure if less prone to floating point error, probably not).

EDIT : You can check if the sum of vectors is in sqrt(2)-0.0001 to sqrt(2)+0.0001 domain to know if they're perpendicular.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service