this seems to be working. i will add it to my posted code soon
pending however is the case of a rotated ellipse
the math in this code calculates the intercting points of a line thru an ellipse in 2d.
the key i was looking for was the A,B,C values of the quadratic setup
A1 = (1 / (dy1/dx1))^2 + (cr1 / cr2)^2
B1 = (2 / (dy1/dx1)) * ((ax1-cx1) - (ay1-cy1) / (dy1/dx1))
C1 = ((ax1-cx1) - (ay1-cy1) / (dy1/dx1))^2 - cr1^2
Code: Select all
ax1=lines(aintersect,1)'ax1,ay1 are the x,y values of one end of line
ay1=lines(aintersect,2)
ax2=lines(aintersect,4)'ax2,ay2 are the x,y values of the of the other end of the line
ay2=lines(aintersect,5)
cx1=circles(bintersect,1)'cx1,cy1 are the values of the center of the ellipse
cy1=circles(bintersect,2)
cr1=circles(bintersect,4)'cr1,cr2 are the major & minor radius values of the ellipse
cr2=circles(bintersect,8)
dx1 = ax2 - ax1'dx1 is the X distance between the end points of a line
dy1 = ay2 - ay1'dy1 is the Y distance between the end points of a line
A1 = (1 / (dy1/dx1))^2 + (cr1 / cr2)^2
B1 = (2 / (dy1/dx1)) * ((ax1-cx1) - (ay1-cy1) / (dy1/dx1))
C1 = ((ax1-cx1) - (ay1-cy1) / (dy1/dx1))^2 - cr1^2
det=B1^2 - 4 * A1 * C1
intersection="outside"
If dy1=0 Then
If ay1-cy1<=cr2 Then
intersection="inside"
fym1=(ay1-cy1)
fym2=(ay1-cy1)
fxm1= cr1 * Sqr(1 - ((ay1-cy1) / cr2)^2)
fxm2= -fxm1
End if
Else
If det>0 Then
intersection="inside"
det=Abs(det)
fym1 = (-B1 + Sqr(det)) / (2 * A1)
fym2 = (-B1 - Sqr(det)) / (2 * A1)
fxm1 = (fym1 - (ay1-cy1)) / (dy1/dx1) + (ax1-cx1)
fxm2 = (fym2 - (ay1-cy1)) / (dy1/dx1) + (ax1-cx1)
EndIf
End If
If intersection="inside" then
fxm1=fxm1+cx1
fxm2=fxm2+cx1
fym1=fym1+cy1
fym2=fym2+cy1
if sqr((mousex-fxm1)^2 + (mousey-fym1)^2) < sqr((mousex-fxm2)^2 + (mousey-fym2)^2) Then
fxm=fxm1
fym=fym1
Else
fxm=fxm2
fym=fym2
End If
End if