IsLineParallelTo() and get2DLineLineInt()
Rhino.LineLineIntersection and Rhino.IsVectorParallelTo methods are problematic..
I spent quite an amount of time trying to find out where my offset script fails,
and then I realized Rhino.LineLineIntersection is not working as expected in many cases.
for example, it doesn’t make intersection where there is obviously one. or
it determines two lines are parallel with very big tolerence. (I think 1 degree)
Then I tried to write my own method returning intersection point of
two lines myself.. but then I found that Rhino.IsVectorParallelTo is also not working
as expected for similar reason : no control of tolerence in determining if lines are parallel or not.
So I wrote that too, with Rhino.Angle2 . I guess these methods will be updated in next SR.
'-------------------------------------------------------------- ' returns true if Parallel '-------------------------------------------------------------- Function IsLineParallelTo(arrLine1, arrLine2, dblTolerence) Dim angle : angle = Rhino.Angle2 (arrLine1, arrLine2)(0) If angle < dblTolerence Then IsLineParallelTo = vbTrue Else IsLineParallelTo = vbFalse End If End Function
also, my own get2DLineLineInt method is written as following :
'-------------------------------------------------------------- ' returns arrPoint at intersection ' arrLine1 = Array((x1,y1),(x2,y2)) ' arrLine2 = Array((x3,y3),(x4,y4)) '-------------------------------------------------------------- Function get2DLineLineInt(arrLine1,arrLine2) Dim x1,y1,x2,y2 Dim x3,y3,x4,y4 Dim X,Y x1 = arrLine1(0)(0) y1 = arrLine1(0)(1) x2 = arrLine1(1)(0) y2 = arrLine1(1)(1) x3 = arrLine2(0)(0) y3 = arrLine2(0)(1) x4 = arrLine2(1)(0) y4 = arrLine2(1)(1) X = ((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) Y = ((x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) get2DLineLineInt = Array(X,Y) End Function
now my script runs smooth without Rhino.LineLineIntersection !! :)
Categorised as: Generative design
Leave a Reply