How to determine if two straight lines are collinear, And can set tolerances for distance and angle,What method should I use to implement this function
I would probably make an A -B testing of the tangency of the two lines and compare the tangency vectors with each other. You might have to first check if the tangency needs to be flipped first… For the tolerance I would take the x, y, z val and use a tolerance value and if it’s inside this tolerance it would return true. Are you using pure Grasshopper or C# / Python?
Using Python
LineCo-Linear.gh (3.7 KB)
Here would be a solution (Just with angle tolerance and in c#)
This seems to have some issues when the tolerance is very small
You can compute the distance from the endpoints of one line onto the infinite of the other:
231023_Colinear_00.gh (5.8 KB)
If you also want to check angles, you can use the properties/methods we talked about over here:
What is this
Test for both of:
Vector → Vector → Cross Product, L == 0 (or L < tol)
Curve → Analysis → Curve Proximity, and D == 0
I don’t think I’ve overlooked an edge case. The Cross Product ==0 test is easily thrown off by floating point inaccuracies, so < tol may be preferable.
two_curves_colinear.gh (7.5 KB)
I don’t know what the Python equivalents of cross product and proximity are (it’s probably a Numpy or Scipy thing), but if calls to NodeInCode to recreate the above GH definition work, then they’re not needed and you don’t need to process the Rhino or Grasshopper curve information yourself in Python then either.
Thank you, it has been resolved