Python求已知点在椭圆上的投影点
Python find the projection point of a known point on an ellipse
我需要实现这个过程:
关于下图,我知道红点的坐标。我必须找到红色点在椭圆中的投影,因此是椭圆的紫色点。
我有橙色线的点和椭圆的点。
是否有可用的算法来执行此操作?
您可以在红色点处构造一个具有非直角顶点的直角三角形,然后这将允许您计算从投影点到橙色线的距离,该投影点与紫色点的长度相同。
三角形构造可以从在红点之间构造一条线 (A) 开始,找到原点和橙色线之间的角度(角度 B)。从那里开始,A 线和右顶点线之间的角度由 90-(角度 B)给出。然后是和弦的长度。
让"center"红点c到另一个红点r的向量为 u,从中心红色点到橙色线上其他点的矢量为v。我们想将 u 旋转 u 和 v 之间的两倍角度。令 θ 为 u 和 v 之间的夹角。我们可以拿 rotation matrix of twice θ, and multiply it by u to get the vector from the red "center" point c to the purple point p. Since we know the cosine of the angle between the red-points-line and the orange line in terms of the points, we shouldn't have to take any sines or cosines of angles or anything, we can just express it all in vector dot product 之类的
人们可能可以将其简化为一个更简单的方程式,但这是一种反映 "showing your work":
的算法
求余弦(θ)为u * v / ||u|| ||v||
使用double angle and pythagorean恒等式
从余弦(θ)求余弦(2θ)和正弦(2θ)
旋转矩阵乘以u得到w,向量来自c 到 p
将w的分量加到c的坐标上得到的坐标p
鉴于您没有指定点和线方程的确切形式,我将假定以下符号:橙色线穿过原点并沿着向量 [v1,v2]
,使得可以写成a*[v1,v2]
。鉴于此,以下方法应该有效:
找到任何与 v 垂直的矢量(我将其称为 n):具有非零 n2 的 n=[-(v2*n2)/v1, n2]
形式的任何矢量。
通过沿着 n 的红点(不是原点)绘制直线:[r1,r2]+b*[-(v2*n2)/v1, n2]
描述任何这样的点。
找到参数 a 和 b,这些线相交:求解 av1=r1-b(v2*n2)/v1 和 a* a 和 b 的 v2=r2*b*n2。您需要的 b 的结果由以下公式给出:
b= (v1*(r1*v1-r2*v1))/(n2*(v1^2 + v2^2))
无论您选择什么 n2,紫色点的坐标都会是 [r1,r2]+2*b*[-(v2*n2)/v1, n2]
。
由于椭圆关于给定的线对称,你只需要计算点关于线的反射。
这里x1
和y1
是红点的坐标,ax+by+c=0
是直线的方程。 x
,y
为反射点坐标
由于直线经过原点,c
为0。
如果您知道直线与 x 轴的夹角 (θ),您可以计算出 a
和 b
的值作为
我们知道 y = x * tan(θ)
和 a x + b y = 0
所以
-a/b = tan(θ)
取b = 1
,a
变为-tan(θ)
参考:https://math.stackexchange.com/questions/1013230/how-to-find-coordinates-of-reflected-point
我需要实现这个过程:
关于下图,我知道红点的坐标。我必须找到红色点在椭圆中的投影,因此是椭圆的紫色点。
我有橙色线的点和椭圆的点。
是否有可用的算法来执行此操作?
您可以在红色点处构造一个具有非直角顶点的直角三角形,然后这将允许您计算从投影点到橙色线的距离,该投影点与紫色点的长度相同。
三角形构造可以从在红点之间构造一条线 (A) 开始,找到原点和橙色线之间的角度(角度 B)。从那里开始,A 线和右顶点线之间的角度由 90-(角度 B)给出。然后是和弦的长度。
让"center"红点c到另一个红点r的向量为 u,从中心红色点到橙色线上其他点的矢量为v。我们想将 u 旋转 u 和 v 之间的两倍角度。令 θ 为 u 和 v 之间的夹角。我们可以拿 rotation matrix of twice θ, and multiply it by u to get the vector from the red "center" point c to the purple point p. Since we know the cosine of the angle between the red-points-line and the orange line in terms of the points, we shouldn't have to take any sines or cosines of angles or anything, we can just express it all in vector dot product 之类的
人们可能可以将其简化为一个更简单的方程式,但这是一种反映 "showing your work":
的算法求余弦(θ)为u * v / ||u|| ||v||
使用double angle and pythagorean恒等式
从余弦(θ)求余弦(2θ)和正弦(2θ)
旋转矩阵乘以u得到w,向量来自c 到 p
将w的分量加到c的坐标上得到的坐标p
鉴于您没有指定点和线方程的确切形式,我将假定以下符号:橙色线穿过原点并沿着向量 [v1,v2]
,使得可以写成a*[v1,v2]
。鉴于此,以下方法应该有效:
找到任何与 v 垂直的矢量(我将其称为 n):具有非零 n2 的
n=[-(v2*n2)/v1, n2]
形式的任何矢量。通过沿着 n 的红点(不是原点)绘制直线:
[r1,r2]+b*[-(v2*n2)/v1, n2]
描述任何这样的点。找到参数 a 和 b,这些线相交:求解 av1=r1-b(v2*n2)/v1 和 a* a 和 b 的 v2=r2*b*n2。您需要的 b 的结果由以下公式给出:
b= (v1*(r1*v1-r2*v1))/(n2*(v1^2 + v2^2))
无论您选择什么 n2,紫色点的坐标都会是
[r1,r2]+2*b*[-(v2*n2)/v1, n2]
。
由于椭圆关于给定的线对称,你只需要计算点关于线的反射。
这里x1
和y1
是红点的坐标,ax+by+c=0
是直线的方程。 x
,y
为反射点坐标
由于直线经过原点,c
为0。
如果您知道直线与 x 轴的夹角 (θ),您可以计算出 a
和 b
的值作为
我们知道 y = x * tan(θ)
和 a x + b y = 0
所以
-a/b = tan(θ)
取b = 1
,a
变为-tan(θ)
参考:https://math.stackexchange.com/questions/1013230/how-to-find-coordinates-of-reflected-point