Kod: Zaznacz cały
ContourPlot[{2 x^2 + 3 y^2 + 4 x*y + 3 x + 2 y + 2 == 0}, {x, -5,
25}, {y, 3, 4}, Mesh -> 5, MeshStyle -> Automatic]
Kod: Zaznacz cały
ContourPlot[{2 x^2 + 3 y^2 + 4 x*y + 3 x + 2 y + 2 == 0}, {x, -5,
25}, {y, 3, 4}, Mesh -> 5, MeshStyle -> Automatic]

Kod: Zaznacz cały
Plot[{a*x^2 + b*x*y + c*y^2 + d*x + e*y + f}, {x, -5, 25}, {y, 3, 4},
Mesh -> 5, MeshStyle -> Automatic] 

Kod: Zaznacz cały
Delta[a_, b_, c_, d_, f_, g_] := -c d^2 + 2 b d f - a f^2 - b^2 g + a c g
J[a_, b_, c_] := -b^2 + a c
i[a_, c_] := a + c
?[-2, 4, -6, 2, 1, 2]Kod: Zaznacz cały
While[True,
(*Randomly choose coefficients until acceptable*)
{a, b, c, d, f, g} = RandomReal[{-10, 10}, 6];
Δ = -c d^2 + 2 b d f - a f^2 - b^2 g + a c g; j = -b^2 + a c; i = a + c;
If[Δ != 0 && j > 0 && Δ/i < 0, Break[]]
];
ellipse = a*x^2 + 2*b*x*y + c*y^2 + 2*d*x + 2*f*y + g;
(*Center of an ellipse in general form is{(c d-b f)/(b^2-a c),(a f-b d)/(b^2-a c)}*)
points = Table[theta = RandomReal[{0, 2 Pi}];
ksol = FindRoot[(ellipse /. {x -> k*Cos[theta] + (c d - b f)/(b^2 - a c),
y -> k*Sin[theta] + (a f - b d)/(b^2 - a c)}) == 0, {k, 1.}];
Point[{x, y}] /. {x -> k*Cos[theta] + (c d - b f)/(b^2 - a c),
y -> k*Sin[theta] + (a f - b d)/(b^2 - a c)} /. ksol, {5}];
nearpoints = points /. Point[{x_, y_}] :> Point[{x + RandomReal[{-.1, .1}], y + RandomReal[{-.1, .1}]}];
(* ellipse x and y min and max values *)
yplotrange = Flatten[{y, Sort[{
( 2*b*d - 2*a*f + Sqrt[(2*b*d - 2*a*f)^2 - 4*(b^2 - a*c)*(d^2 - a*g)])/(2*(-b^2 + a*c)),
(-2*b*d + 2*a*f + Sqrt[(2*b*d - 2*a*f)^2 - 4*(b^2 - a*c)*(d^2 - a*g)])/(2*( b^2 - a*c))}]}];
xplotrange = Flatten[{x, Sort[{
( 2*c*d - 2*b*f + Sqrt[(-2*c*d + 2*b*f)^2 - 4*(b^2 - a*c)*(f^2 - c*g)])/(2*( b^2 - a*c)),
(-2*c*d + 2*b*f + Sqrt[(-2*c*d + 2*b*f)^2 - 4*(b^2 - a*c)*(f^2 - c*g)])/(2*(-b^2 + a*c))}]}];
Show[ContourPlot[ellipse == 0, Evaluate[xplotrange], Evaluate[yplotrange]],
Graphics[points],
Graphics[nearpoints]]
Kod: Zaznacz cały
Panel[Column[{Button["Generuj Elipse",
While[True,(*Randomly choose coefficients until acceptable*){a, b,
c, d, f, g} = RandomReal[{-10, 10}, 6];
[CapitalDelta] = -c d^2 + 2 b d f - a f^2 - b^2 g + a c g;
j = -b^2 + a c; i = a + c;
If[[CapitalDelta] != 0 && j > 0 && [CapitalDelta]/i < 0,
Break[]]];
ellipse = a*x^2 + 2*b*x*y + c*y^2 + 2*d*x + 2*f*y + g;
(*Center of an ellipse in general form is{(c d-b f)/(b^2-
a c),(a f-b d)/(b^2-a c)}*)
points = Table[theta = RandomReal[{0, 2 Pi}];
ksol =
FindRoot[(ellipse /. {x ->
k*Cos[theta] + (c d - b f)/(b^2 - a c),
y -> k*Sin[theta] + (a f - b d)/(b^2 - a c)}) == 0, {k,
1.}];
Point[{x, y}] /. {x -> k*Cos[theta] + (c d - b f)/(b^2 - a c),
y -> k*Sin[theta] + (a f - b d)/(b^2 - a c)} /. ksol, {5}];
nearpoints =
points /.
Point[{x_, y_}] :>
Point[{x + RandomReal[{-.1, .1}], y + RandomReal[{-.1, .1}]}];
(*ellipse x and y min and max values*)
yplotrange =
Flatten[{y,
Sort[{(2*b*d - 2*a*f +
Sqrt[(2*b*d - 2*a*f)^2 -
4*(b^2 - a*c)*(d^2 - a*g)])/(2*(-b^2 + a*c)), (-2*b*d +
2*a*f +
Sqrt[(2*b*d - 2*a*f)^2 -
4*(b^2 - a*c)*(d^2 - a*g)])/(2*(b^2 - a*c))}]}];
xplotrange =
Flatten[{x,
Sort[{(2*c*d - 2*b*f +
Sqrt[(-2*c*d + 2*b*f)^2 -
4*(b^2 - a*c)*(f^2 - c*g)])/(2*(b^2 - a*c)), (-2*c*d +
2*b*f +
Sqrt[(-2*c*d + 2*b*f)^2 -
4*(b^2 - a*c)*(f^2 - c*g)])/(2*(-b^2 + a*c))}]}];
final =
Show[ContourPlot[ellipse == 0, Evaluate[xplotrange],
Evaluate[yplotrange]], Graphics[points],
Graphics[{Red, nearpoints}], ImageSize -> {500, Automatic}]],
Dynamic[final],
Dynamic@Grid[
Join[{{"points", "nearby points"}},
Transpose[{points, nearpoints}][[All, All, 1]]], Frame -> All,
Alignment -> Left]}]]