After the discussion about the intersecting hyperbolae it struck me
that the general equations
eq1 = A*x**2 + B*x*y + C*y**2 + D*x + E*y + F = 0
eq2 = G*x**2 + H*x*y + I*y**2 + J*x + K*y + L = 0
represent many different objects and so the general solution to them
is of ... general purpose. Since these equations end up requiring the
solution of a quartic equations, I solved the system for x and y and
stored them in a routine that can be used to solve for the
intersections of two such quantities quickly.
e.g. here is what it now looks like to solve for the intersection of a
circle and an ellipse:
var("x y c R")
for c in [4,R]: # do it once with a numerical r and again with a
symbolic c
s,r = intersection((x-1)**2/2+(y-2)**2/4-c, x**2+y**2-10, x, y, 3)
for k in sorted(r):
if r[k]:
print (k, r[k]),',',
print
for si in s:
if type(s) is dict:
print si, s[si]
else:
print si
(The numerical results match up with the nice solver/plotter at
wolframalpha.)
c=4
(A, 8) , (C, 4) , (D, -16) , (E, -16) , (F, -40) , (G, 1) , (I, 1) ,
(L, -10) ,
(-1.80, 2.60)
(3.36 + 4.2*I, -4.95 + 2.85*I)
(3.08, -0.707)
(3.36 - 4.2*I, -4.95 - 2.85*I)
c=R
(A, 8) , (C, 4) , (D, -16) , (E, -16) , (F, 24 - 16*R) , (G, 1) , (I,
1) , (L, -10) ,
x 1 + x*(1 + (-512 + 512*R + 512*y - 128*y**2)**(1/2)/16) - (-512 +
512*R + 512*y - 128*y**2)**(1/2)/16
y -516 + 208*R + 208*y - 32*R*y - 16*R**2 + 20*y**2 - 8*R*y**2 -
8*y**3 - y**4
Note that in the symbolic case, the equations to be solved are
returned since a general solution is not generally possible unless
certain discriminants can be determined.
If we solve for the intersection of a parabola and an ellipse we get:
>>> print intersection(y-(x**2-3),(x-1)**2/2+y**2-5,x,y,2)
(set([(-2.0, 0.80), (2.2, 2.1), (0.88, -2.2), (-1.2, -1.6)]), {E: 1,
K: 0, D: 0, J: -4, C: 0, G: 2, I: 4, B: 0, F: 3, H: 0, A: -1, L: -18})
which again match with wolframalpha.
This is commit labelled "Intersections" in my t2 branch. Eventually,
either solve should handle this, but for now it appears as a function
"intersection" in solvers.
Hyperbola could be added to the Geometry class, and any intersections
that aren't already defined there could use this one generic function
for calculating the intersections.
/c
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.