如何创建椭圆形几何体
How to create ellipse shape geometry
如何根据已知轴坐标和峰半径创建椭圆?
来自下图:
A点和B点是已知的
R 是 fresnelZone 计算的结果(以米为单位)。
点 X 是线串 AB 的质心
我还阅读了:
this
和
this
但是不知道怎么实现。
一个人可能会继续,例如:
#!/usr/bin/env python
import math
from shapely.geometry import Point
from shapely.affinity import scale, rotate
#input parameters
A = Point(1, 1)
B = Point(4, 5)
R = 1
d = A.distance(B)
#first, rotate B to B' around A so that |AB'| = |AB| and B'.y = A.y
#and then take S as midpoint of AB'
S = Point(A.x + d/2, A.y)
#alpha represents the angle of this rotation
alpha = math.atan2(B.y - A.y, B.x - A.x)
#create a circle with center at S passing through A and B'
C = S.buffer(d/2)
#rescale this circle in y-direction so that the corresponding
#axis is R units long
C = scale(C, 1, R/(d/2))
#rotate the ellipse obtained in previous step around A into the
#original position (positive angles represent counter-clockwise rotation)
C = rotate(C, alpha, origin = A, use_radians = True)
for x,y in C.exterior.coords:
print(x, y)
我正在努力解决类似的问题。
我也想做一个菲涅耳区,但是我想把它画在LOS中,也就是A点和B点的连线。
使用 ewcz 提供的代码,我添加了线条并绘制了所有内容。
结果旋转后的线,不对应椭圆的轴,因此不对应LOS。
#!/usr/bin/env python
import math
from shapely.geometry import Point, LineString
from shapely.affinity import scale, rotate
from matplotlib import pyplot as plt
#input parameters
A = Point(0, 0)
B = Point(400, 10)
R = 5
d = A.distance(B)
#first, rotate B to B' around A so that |AB'| = |AB| and B'.y = A.y
#and then take S as midpoint of AB'
S = Point(A.x + d/2, A.y)
#Make a straight line
LOS = LineString([(A.x, A.y), (B.x, A.y)])
#alpha represents the angle of this rotation
alpha = math.atan2(B.y - A.y, B.x - A.x)
#create a circle with center at S passing through A and B'
C = S.buffer(d/2)
#rescale this circle in y-direction so that the corresponding
#axis is R units long
C = scale(C, 1, R/(d/2))
#rotate the ellipse obtained in previous step around A into the
#original position (positive angles represent counter-clockwise rotation)
C = rotate(C, alpha, origin=A, use_radians=True)
f_x, f_y = C.exterior.xy
#plot the ellipse
plt.plot(f_x, f_y)
#rotate the line in the same way as the ellipse
LOS_R = rotate(LOS, alpha, origin=A, use_radians=True)
f_x, f_y = LOS_R.xy
#plot the line
plt.plot(f_x, f_y)
plt.show()
结果图是:
Plotted image with matplot
如何根据已知轴坐标和峰半径创建椭圆?
来自下图:
A点和B点是已知的
R 是 fresnelZone 计算的结果(以米为单位)。
点 X 是线串 AB 的质心
我还阅读了: this 和 this 但是不知道怎么实现。
一个人可能会继续,例如:
#!/usr/bin/env python
import math
from shapely.geometry import Point
from shapely.affinity import scale, rotate
#input parameters
A = Point(1, 1)
B = Point(4, 5)
R = 1
d = A.distance(B)
#first, rotate B to B' around A so that |AB'| = |AB| and B'.y = A.y
#and then take S as midpoint of AB'
S = Point(A.x + d/2, A.y)
#alpha represents the angle of this rotation
alpha = math.atan2(B.y - A.y, B.x - A.x)
#create a circle with center at S passing through A and B'
C = S.buffer(d/2)
#rescale this circle in y-direction so that the corresponding
#axis is R units long
C = scale(C, 1, R/(d/2))
#rotate the ellipse obtained in previous step around A into the
#original position (positive angles represent counter-clockwise rotation)
C = rotate(C, alpha, origin = A, use_radians = True)
for x,y in C.exterior.coords:
print(x, y)
我正在努力解决类似的问题。 我也想做一个菲涅耳区,但是我想把它画在LOS中,也就是A点和B点的连线。
使用 ewcz 提供的代码,我添加了线条并绘制了所有内容。
结果旋转后的线,不对应椭圆的轴,因此不对应LOS。
#!/usr/bin/env python
import math
from shapely.geometry import Point, LineString
from shapely.affinity import scale, rotate
from matplotlib import pyplot as plt
#input parameters
A = Point(0, 0)
B = Point(400, 10)
R = 5
d = A.distance(B)
#first, rotate B to B' around A so that |AB'| = |AB| and B'.y = A.y
#and then take S as midpoint of AB'
S = Point(A.x + d/2, A.y)
#Make a straight line
LOS = LineString([(A.x, A.y), (B.x, A.y)])
#alpha represents the angle of this rotation
alpha = math.atan2(B.y - A.y, B.x - A.x)
#create a circle with center at S passing through A and B'
C = S.buffer(d/2)
#rescale this circle in y-direction so that the corresponding
#axis is R units long
C = scale(C, 1, R/(d/2))
#rotate the ellipse obtained in previous step around A into the
#original position (positive angles represent counter-clockwise rotation)
C = rotate(C, alpha, origin=A, use_radians=True)
f_x, f_y = C.exterior.xy
#plot the ellipse
plt.plot(f_x, f_y)
#rotate the line in the same way as the ellipse
LOS_R = rotate(LOS, alpha, origin=A, use_radians=True)
f_x, f_y = LOS_R.xy
#plot the line
plt.plot(f_x, f_y)
plt.show()
结果图是: Plotted image with matplot