I’m looking for a way to check whether two parallel lines are inline/aligned or not!? The solution should be independent of the position of the lines in world space, meaning that it shouldn’t rely on comparisons to world axes.
Whether the lines overlap each other partially, have an intersection at one of their end points, or don’t come into contact at all doesn’t matter! The case where both lines could be exactly the same was previously excluded.
I want to incorporate this strategy in a larger Python script, but a vanilla Grasshopper strategy, reliant on math, is also welcome!
Thanks @PeterFotiadis, but I don’t get how this could help me?
I already know that my lines are parallel, meaning that the slope of the first line is equal to the slope of the second line (m1 = m2).
I’m also unsure what the Y and X values represent, or how to use the Y value to evaluate if parallel lines are aligned?
def get_slope(line):
"""Returns the slope of a line."""
dx = line.To.X - line.From.X
if dx != 0:
return (line.To.Y - line.From.Y) / dx
def get_y(line, x):
m = get_slope(line)
b = line.From.Y - (m * line.From.X)
return m * x + b
print "Y for Line A:", get_y(LineA, LineB.From.X)
print "Y for Line B:", get_y(LineB, LineA.From.X)
I also understand some C#, if you are uncomfortable with Python.
Unfortunately, not what I’m looking for. I’m aiming to see if parallel lines (not curves) are aligned/inline, even if they aren’t touching. I guess I could check for intersections of infinite lines, but maybe there’s a smarter solution. Thanks anyway!
line.ToNurbsCurve() solves that for you btw.
In that case, go with LineLine intersection as Anders also suggested, nothing much smarter than a simple function call.
Thanks again, @PeterFotiadis! This seems to work, but I’m curious what your other script is going to look like.
@AndersDeleuran and @rgr, line-line-intersections can’t be found for parallel lines!
Since, I already know that all my lines are parallel, this method won’t work for weeding out aligned, parallel lines (cf. “Remarks” Documentation).
I’d use
Line.DistanceTo (with the limitToFiniteSegment option set to false)
to check whether both ends of one line lie (within some tolerance) on the infinite extension of the other
Well … it may look a bit freaky (implementing various “options”/freaky things like the determinant of a 3*3 coord Matrix) … but I haven’t found time to do it (yet). In the mean time:
on the basis that two lines are aligned if they have a common unit vector and the line between their start points has the same unit vector (or their start points coincide).
here is my two cents,
it uses native components only ,just make sure the extension value is large enough to force an intersection ,according to your lengths and units.