3
$\begingroup$

How to optimize the two tangents of a circle by passing through a point outside the circle and calculate the sine value of the angle between the two tangents?

The equation for a circle is: x ^ 2+y ^ 2-4 x -1==0

The point outside the circle is: {0, -2}

Draw two tangents of circle x ^ 2+y ^ 2-4 x -1==0 through {0, -2}

The angle between two tangent lines is a, find Sin [a]

My attempt is as follows:

Clear["Global`*"]
eqn = x^2 + y^2 - 4 x - 1 == 0;
rule = SolveAlways[{Apply[Subtract]@eqn == 
     dd ((x - aa)^2 + (y - bb)^2 - cc)}, {x, y}][[1]]
(x - aa)^2 + (y - bb)^2 == cc /. rule
{{aa, bb}, Sqrt[cc]} /. rule
eqs = {{0, -2}, x^2 + y^2 - 4 x - 1 == 0};
reg = ImplicitRegion[y + 2 == k x, {x, y}];
pt = {2, 0};
RegionDistance[reg, pt];
Reduce[RegionDistance[reg, pt] == Sqrt[5], k]
eqs2 = {y + 2 == (-4 - Sqrt[15]) x, y + 2 == (-4 + Sqrt[15]) x}
tan\[Alpha] = (-4 - Sqrt[15] - (-4 + Sqrt[15]))/(
  1 + (-4 - Sqrt[15]) (-4 + Sqrt[15])) // FullSimplify
Reduce[{Sin[\[Alpha]] == -Sqrt[15] Cos[\[Alpha]], 
  Sin[\[Alpha]]^2 + Cos[\[Alpha]]^2 == 1, t == Sin[\[Alpha]]}, t]
ContourPlot[Evaluate@{eqs, eqs2}, {x, -1, 5}, {y, -3, 3}, 
 Epilog -> {Red, PointSize[0.01], Point[{0, -2}]}, 
 PlotLegends -> Placed[eqs, {0.8, 0.15}], AspectRatio -> Automatic, 
 Frame -> False, Axes -> True, AxesStyle -> Arrowheads[{0.0, 0.04}], 
 AxesLabel -> {x, y}, ImageSize -> Full]

Are there any other good methods or ways to optimize the code? The best code is universal, capable of inputting equations for any circle and a point outside any circle, automatically generating tangent equations, drawing images, and calculating corresponding values.

$\endgroup$

1 Answer 1

5
$\begingroup$
  • The normal of the tangent line of a implicit curve f[x,y]==0 is it's Grad[f[x,y],{x,y}].The tangent line which through the point {x,y} on the curve can be writed as {Grad[f[x, y], {x, y}] . ({X, Y} - {x, y}) == 0 where {X,Y} is the point on the tangent line.
Clear["Global`*"];
f[x_, y_] = x^2 + y^2 - 4 x - 1;
con = ContourPlot[f[x, y] == 0, {x, -5, 5}, {y, -5, 5}];
pt = {0, -2};
sols = SolveValues[{Grad[f[x, y], {x, y}] . ({X, Y} - {x, y}) == 0 /. 
    Thread[{X, Y} -> pt], f[x, y] == 0}, {x, y}, Reals]

Graphics[{InfiniteLine[{#, pt}] & /@ sols, Red, AbsolutePointSize[5], 
  Point[sols], Blue, Point[pt], con // First}]
  • The tangent points

enter image description here

enter image description here

  • We can test another curve in implicit form.
f[x_, y_] = x^2 - y^2 - y*x + x^5 + 1;

enter image description here

$\endgroup$
3
  • $\begingroup$ Can we display the two tangent equations? $\endgroup$
    – csn899
    Commented Jun 12, 2023 at 9:02
  • 1
    $\begingroup$ @csn899 Grad[f[x, y], {x, y}] . ({X, Y} - {x, y}) == 0 /. Thread[{x, y} -> #] & /@ sols // FullSimplify $\endgroup$
    – cvgmt
    Commented Jun 12, 2023 at 9:05
  • 1
    $\begingroup$ @csn899 VectorAngle[sols[[1]] - pt, sols[[2]] - pt] // Sin // Simplify $\endgroup$
    – cvgmt
    Commented Jun 12, 2023 at 9:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.