Дистанция 3D:
Function Distance3D#(x1#,y1#,z1#,x2#,y2#,z2#)
Return Sqr((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)
End Function
Пересечение линий:
Global Intersection_X#
Global Intersection_Y#
Global Intersection_AB#
Global Intersection_CD#
Function LinesIntersect(Ax#, Ay#, Bx#, By#, Cx#, Cy#, Dx#, Dy#)
Rn# = (Ay#-Cy#)*(Dx#-Cx#) - (Ax#-Cx#)*(Dy#-Cy#)
Rd# = (Bx#-Ax#)*(Dy#-Cy#) - (By#-Ay#)*(Dx#-Cx#)
If Rd# = 0
Return False ; Lines are parralel.
Else
Sn# = (Ay#-Cy#)*(Bx#-Ax#) - (Ax#-Cx#)*(By#-Ay#)
Intersection_AB# = Rn# / Rd#
Intersection_CD# = Sn# / Rd#
Intersection_X# = Ax# + Intersection_AB#*(Bx#-Ax#)
Intersection_Y# = Ay# + Intersection_AB#*(By#-Ay#)
Return True
EndIf
End Function
2Д точка об 2д треугольник
Function PointInTri(Px#, Py#, V0x#, V0y#, V1x#, V1y#, V2x#, V2y#)
; vector(e1,v1,v0)
E1x# = V1x# - V0x#
E1y# = V1y# - V0y#
; vector(e2,v2,v0)
E2x# = V2x# - V0x#
E2y# = V2y# - V0y#
; crossproduct(h,d,e2)
Hx# = -E2y#
Hy# = E2x#
; a = dotproduct(e1,h)
A# = (E1x# * Hx#) + (E1y# * Hy#)
F# = 1.0 / A#
; vector(s,p,v0)
Sx# = Px# - V0x#
Sy# = Py# - V0y#
;u = f * (dotProduct(s,h))
U# = F# * ((Sx# * Hx#) + (Sy# * Hy#))
; If the value of the U coordinate is outside the range of values inside the triangle,
; then the ray has intersected the plane outside the triangle.
If (U# < 0) Or (U# > 1)
Return False
EndIf
; crossProduct(q,s,e1)
Qz# = (Sx# * E1y#) - (E1x# * Sy#)
; v = f * dotProduct(d,q)
V# = F# * Qz#
; If the value of the V coordinate is outside the range of values inside the triangle,
; then the ray has intersected the plane outside the triangle.
If (V# < 0) Or (V# > 1) Then Return False
; U + V together cannot exceed 1.0 or the point is not in the triangle.
; If you imagine the triangle as half a square this makes sense. U=1 V=1 would be in the
; lower left hand corner which would be in the second triangle making up the square.
If (U# + V#) > 1 Then Return False
; The point was in the triangle. Yay!
Return True
; Note that you could also return the U and V coordinates calculated in this function
; if you need those values!
End Function
Столкновение с неповёрнутым прямоугольником
Function PointInRect(iPointX,iPointY,iXPos1,iYPos1,iXPos2,iYPos2)
iXPos2=iXPos2 + iXPos1
iYPos2=iYPos2 + iYPos1
Return ((((iPointX-iXPos1) Xor (iPointX-iXPos2)) And ((iPointY-iYPos1) Xor (iPointY-iYPos2))) And $80000000)
End Function
Твои овалы это не овалы, а обычная Distance2D:
Function Distance2D#(x1#,y1#,x2#,y2#)
Local nx#=x1-x2 ;Длина горизонтального Катета
Local ny#=y1-y2 ;Длина Вертикального Катета
Return Sqr((nx*nx)+(ny*ny)) ;Длина Гипотенузы
End Function