1 /* Intersection of two conics
2 David Billinghurst, 2021-09-02
7 "intersection of two arbitrary conics"$
9 eq1: a1*x^2+b1*x*y+c1*y^2+d1*x+e1*y+f1$
10 eq2: a2*x^2+b2*x*y+c2*y^2+d2*x+e2*y+f2$
17 "New variables to simplify."$
25 eq3: a3*x^2+b3*x*y+d3*x+e3*y+f3;
27 "Show (eq3a) is equal to (eq3)"$
28 expand(eq3-eq3a),subs;
32 This step can't be performed when b_3*x + e_3 = 0. This is not uncommon
33 For example, it will happen if both conics are centred on the x-axis.
35 If b3=0 and e3=0 then (eq3) is already free of y and can be solved for x.
36 When it occurs we should be able to substitute our solution for x into (eq1)
37 and (eq2) and solve for y. There may be spurious solutions that do not
38 satisfy both equations.
40 The case x=0 and e_3=0 should be investigated."$
45 "Substitute (eq4) into (eq1). Multiply through by denominator"$
51 "eq6 is a quartic in x, k4*x^4+k3*x^3+k2*x^2+k1*x+k0"$
57 "Confirm eq6-k4*x^4+k3*x^3+k2*x^2+k1*x+k0 = 0"$
58 expand(eq6-(k4*x^4+k3*x^3+k2*x^2+k1*x+k0));
62 "Ellipse centred at origin with semi-major axis 2 and 1"$
63 ellipse:(x/2)^2+y^2-1;
64 ellipse:expand(ellipse);
65 "Create a list of coefficients for later use"$
66 coeffs_1:[a1=1/4,b1=0,c1=1,d1=0,e1=0,f1=-1];
68 "Circle centre (3,0) radius 2"$
69 circle:(x-3)^2+y^2-2^2;
70 circle:expand(circle);
71 coeffs_2:[a2=1,b2=0,c2=1,d2=-6,e2=0,f2=5];
73 "Generate a list of coefficients to substitute"$
74 coeffs:subs,coeffs_1,coeffs_2;
75 coeffs:append(coeffs,coeffs_1,coeffs_2);
81 p:s4*x^4+s3*x^3+s2*x^2+s1*x+s0;
83 "Solve quartic p and select real roots. Only one (multiple) root"$
89 Could try eq4: y = -(a3*x^2+d3*x+f3)/(b3*x+e3), but in this case b3=0
90 and e3=0 so divide by zero
92 Alternatively substitute x into either conic eqn and solve for y, then
94 solutions as some may be spurious."$
101 "Check if roots satisfy other equation circle"$
105 kill(ellipse,x1,y1,y2,coeffs_1,coeffs,p,s0,s1,s2,s3,s4);
110 Ellipse centred at origin
111 semi-major axis length 2 in direction x=-y
112 semi-minor axis length 1 in direction x=y
114 Same circle centre (3,0) radius 2"$
116 ellipse:(5*y^2)/8+(3*x*y)/4+(5*x^2)/8-1;
117 ellipse:expand(ellipse);
118 coeffs_1:[a1=5/8,b1=3/4,c1=5/8,d1=0,e1=0,f1=-1];
120 coeffs:subs,coeffs_1,coeffs_2;
121 coeffs:append(coeffs,coeffs_1,coeffs_2);
127 p:s4*x^4+s3*x^3+s2*x^2+s1*x+s0;
130 "Select the real roots"$
134 "Use eq4 as b3*x+e3 /= 0"$
135 y1:rhs(eq4),x=x1,coeffs;
136 y2:rhs(eq4),x=x2,coeffs;
142 "Or substitute x into conic equations, solve for y and select common roots"$
143 allroots(subst(x=x1,circle));
144 allroots(subst(x=x1,ellipse));
145 allroots(subst(x=x2,circle));
146 allroots(subst(x=x2,ellipse));