Thanks to all the help regarding Maths.
I was having trouble getting this method to work. I am pretty sure I understand what it is meant to do and that is detect non-segmented line intersection.
I was wondering if changes regarding my ‘LineShape’ class have gave in the wrong input to the method.
I have spent quite a bit of time researching geometry including vectors, magnitude, direction and line to line intersection.
Here is the project file (detecting parallel lines or any kind of intersection does not seem to work at all):
https://www.dropbox.com/s/crh295jhjwiaafz/DEBUG.xojo_binary_project?dl=0
Here is the modified method:
Function Intersects(other as LineShape, intersectionPoint as Xojo.Core.Point) As boolean
dim A1, A2, B1, B2 as Xojo.Core.Point
A1 = FromPoint
A2 = ToPoint
B1 = other.FromPoint
B2 = other.ToPoint
dim Aslope as Double = (A2.Y - A1.Y) / (A2.X - A1.X)
dim Bslope as Double = (B2.Y - B1.Y) / (B2.X - B1.X)
dim AIntercept as Double = A1.Y - Aslope*A1.X
dim BIntercept as Double = B1.Y - Bslope*B1.X
if Aslope = Bslope then //parallel lines
if AIntercept <> BIntercept then
Return False
else
Return True
end if
end if
dim XIntersection as Double = (BIntercept-AIntercept)/(Aslope-Bslope)
dim YIntersection as Double = Aslope*XIntersection + AIntercept
intersectionPoint = new xojo.Core.Point(XIntersection,YIntersection)
Return True
End Function
Thanks