from typing import Tuple
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np
def find_tangent_lines(
center: Tuple[float, float],
semi_axes: Tuple[float, float],
rotation: float,
reference_point: Tuple[float, float],
):
"""Find the Ellipse's two tangents that go through a reference point.
Args:
center: The center of the ellipse.
semi_axes: The semi-major and semi-minor axes of the ellipse.
rotation: The counter-clockwise rotation of the ellipse in radians.
reference_point: The coordinates of the reference point.
Returns:
(m1, h1): Slope and intercept of the first tangent.
(m2, h2): Slope and intercept of the second tangent.
"""
x0, y0 = center
a, b = semi_axes
s, c = np.sin(rotation), np.cos(rotation)
p0, q0 = reference_point
A = (-a**2*s**2 - b**2*c**2 + (y0-q0)**2)
B = 2*(c*s*(a**2-b**2) - (x0-p0)*(y0-q0))
C = (-a**2*c**2 - b**2*s**2 + (x0-p0)**2)
if B**2 - 4*A*C < 0:
raise ValueError('Reference point lies inside the ellipse')
t1, t2 = (
(-B + np.sqrt(B**2 - 4*A*C))/(2*A),
(-B - np.sqrt(B**2 - 4*A*C))/(2*A),
)
return (
(1/t1, q0 - p0/t1),
(1/t2, q0 - p0/t2),
)
c = Bekannter äußerer Punkt, erwartete Ergebnisse A (x, y), b (x1, y1) < /p>
Ich denke, die Antwort könnte hier in der ersten Antwort versteckt werden, wodurch Tangentenhänge und Abschnitte berechnet werden. Ich nehme an.[code]from typing import Tuple
import matplotlib.pyplot as plt from matplotlib.patches import Ellipse import numpy as np
def find_tangent_lines( center: Tuple[float, float], semi_axes: Tuple[float, float], rotation: float, reference_point: Tuple[float, float], ): """Find the Ellipse's two tangents that go through a reference point.
Args: center: The center of the ellipse. semi_axes: The semi-major and semi-minor axes of the ellipse. rotation: The counter-clockwise rotation of the ellipse in radians. reference_point: The coordinates of the reference point.
Returns: (m1, h1): Slope and intercept of the first tangent. (m2, h2): Slope and intercept of the second tangent. """ x0, y0 = center a, b = semi_axes s, c = np.sin(rotation), np.cos(rotation) p0, q0 = reference_point
A = (-a**2*s**2 - b**2*c**2 + (y0-q0)**2) B = 2*(c*s*(a**2-b**2) - (x0-p0)*(y0-q0)) C = (-a**2*c**2 - b**2*s**2 + (x0-p0)**2)
if B**2 - 4*A*C < 0: raise ValueError('Reference point lies inside the ellipse')
Ich versuche, die Imagesharp -Bibliothek zu verwenden, um einen Kreis innerhalb eines Bildes zu definieren - und alle Pixel innerhalb oder außerhalb des Kreises transparent zu machen. Mein Code ist:...
Ich habe eine Ellipse, definiert durch Mittelpunkt, RadiusX und RadiusY, und ich habe einen Punkt. Ich möchte den Punkt auf der Ellipse finden, der dem angegebenen Punkt am nächsten liegt. In der...