[英]How to find a point coordinates on rotated ellipse?
I already checked below questions:我已经检查了以下问题:
Plot Ellipse with matplotlib.pyplot (Python) Plot 椭圆与 matplotlib.pyplot (Python)
How to find the point on ellipse given the angle 如何在给定角度的椭圆上找到点
I'm trying to find a point coordinates on rotated ellipse, actually I need the point coordinates that can be shown on image.我试图在旋转椭圆上找到一个点坐标,实际上我需要可以在图像上显示的点坐标。
Here is the code, most of the them from the first SO question.这是代码,其中大部分来自第一个 SO 问题。
u=1. #x-position of the center
v=0.5 #y-position of the center
a=2. #radius on the x-axis
b=1.5 #radius on the y-axis
t_rot=pi/4 #rotation angle
angle = 15 # always on blue circle
t = np.linspace(0, 2*pi, 100)
Ell = np.array([a*np.cos(t) , b*np.sin(t)])
#u,v removed to keep the same center location
R_rot = np.array([[cos(t_rot) , -sin(t_rot)],[sin(t_rot) , cos(t_rot)]])
#2-D rotation matrix
Ell_rot = np.zeros((2,Ell.shape[1]))
for i in range(Ell.shape[1]):
Ell_rot[:,i] = np.dot(R_rot,Ell[:,i])
#ellipses
plt.plot( u+Ell[0,:] , v+Ell[1,:] ) #initial ellipse
plt.plot( u+Ell_rot[0,:] , v+Ell_rot[1,:],'magenta' ) #rotated ellipse
#points
plt.scatter(u,v,s=10,color='black') # center
plt.scatter(u + a*cos(angle),v + b*sin(angle),s=50,color='black') #point on blue ellipse
plt.grid(color='lightgray',linestyle='--')
plt.show()
If I change the angle I got a point on not-rotated ellipse(black point).如果我改变角度,我会在未旋转的椭圆(黑点)上得到一个点。
What I want to do is find the points on the rotated ellipse that I tagged artificially with red.我想要做的是找到我用红色人为标记的旋转椭圆上的点。 Basically these are the points on ellipse which have minimum&maximum xy values.
基本上这些是椭圆上具有最小和最大 xy 值的点。
Any suggestions?有什么建议么?
Thanks a lot!非常感谢!
This, like many questions about ellipses, can easily be answered by representing an ellipse as the set of points p such that就像许多关于椭圆的问题一样,这可以通过将椭圆表示为点 p 的集合来轻松回答,使得
p'*inv(C)*p = 1
where C is a symmetric (indeed positive definite) 2x2 matrix
In the case of an (unrotated) matrix with semi-major axis a and semi-minor axis b we have对于具有半长轴 a 和半短轴 b 的(未旋转的)矩阵,我们有
C = (a*a 0 )
( 0 b*b)
The rotated (via a rotation matrix R) ellipse is represented by旋转(通过旋转矩阵 R)椭圆表示为
p'*inv(D)*p = 1
where D = R*C*R'
If p is a point on the ellipse, the vector如果 p 是椭圆上的一个点,则向量
n = inv(D)*p
is at right angles to the tangent to the ellipse at p.与椭圆在 p 处的切线成直角。 In your case, the points at maximum and minimum x have normals to their tangents that are vertical;
在您的情况下,最大和最小 x 处的点具有垂直切线的法线; similarly the points at maximum and minimum y have normals to their tangents that are horizontal.
类似地,最大值和最小值 y 处的点具有水平切线的法线。
So, for example to find the point at maximum y, we:因此,例如要找到最大 y 处的点,我们:
put n = (0,1)
compute p = D*n (ie solve n = inv(D)*p for p)
But we need to scale this point so it is on the ellipse;但是我们需要缩放这个点,使它在椭圆上; a little algebra shows the appropriate point p is
一点代数显示适当的点 p 是
p = D*n / sqrt( n'*D*n)
The point at minimum y is -p.最小 y 的点是 -p。 For the points at minimum/maximum x, we start with n = (1,0)
对于最小/最大 x 处的点,我们从 n = (1,0) 开始
I was able to draw the bounding boxes that Robert suggest and it worked我能够绘制罗伯特建议的边界框并且它有效
Here is what I've added to calculate the lines这是我添加的用于计算线条的内容
xa = np.sqrt((a**2*np.cos(t_rot)**2)+(b**2*np.sin(t_rot)**2))
ya = np.sqrt((a**2*np.sin(t_rot)**2)+(b**2*np.cos(t_rot)**2))
And here is the full code:这是完整的代码:
u=3 #x-position of the center
v=6 #y-position of the center
a=np.sqrt(2) #radius on the x-axis
b=1 #radius on the y-axis
t_rot=pi/6 #rotation angle
t = np.linspace(0, 2*pi, 100)
Ell = np.array([a*np.cos(t) , b*np.sin(t)])
#u,v removed to keep the same center location
R_rot = np.array([[cos(t_rot) , -sin(t_rot)],[sin(t_rot) , cos(t_rot)]])
#2-D rotation matrix
Ell_rot = np.zeros((2,Ell.shape[1]))
for i in range(Ell.shape[1]):
Ell_rot[:,i] = np.dot(R_rot,Ell[:,i])
xa = np.sqrt((a**2*np.cos(t_rot)**2)+(b**2*np.sin(t_rot)**2))
ya = np.sqrt((a**2*np.sin(t_rot)**2)+(b**2*np.cos(t_rot)**2))
#ellipses
plt.plot( u+Ell_rot[0,:] , v+Ell_rot[1,:],'magenta') #rotated ellipse
#points
plt.scatter(u,v,s=10,color='black') # center
#bounding box lines
plt.axhline(y=ya+v,color='r',label=str(ya+v))
plt.axhline(y=-ya+v,color='b',label=str(-ya+v))
plt.axvline(x=xa+u, color='g',label=str(xa+u))
plt.axvline(x=-xa+u, color='y',label=str(-xa+u))
plt.legend()
plt.grid(color='lightgray',linestyle='--')
plt.show()
Here is the visual:这是视觉效果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.