[英]How to align two hyperplanes with plane equations
I am trying to Euclidean transform one plane to other plane.我正在尝试将一个平面转换为另一个平面的欧几里得。 I have two equation of planes and they have different sizes.
我有两个平面方程,它们有不同的大小。 How can I align two plane in one coordinate system?
如何在一个坐标系中对齐两个平面?
My two planes in form of ax+by+cz+d=0.我的两架飞机的形式是ax+by+cz+d=0。
first plane => a = -5.297742252442251, b = 21.751836101364013, c = -2.470896764133499, d = -0.5601826186620921第一架飞机 => a = -5.297742252442251,b = 21.751836101364013,c = -2.470896764133499,d = -0.5601826186620921
Second plane => a = 45.42557999642176, b = -16.9433283673388, c = 2.5117971500097287, d = -8.528560240570203]第二个平面 => a = 45.42557999642176,b = -16.9433283673388,c = 2.5117971500097287,d = -8.528560240570203]
For plotting on the matplotlib, I used following code using matplotlib为了在 matplotlib 上绘图,我使用以下代码使用 matplotlib
x = np.linspace(-1,1,100)
y = np.linspace(-1,1,100)
X,Y = np.meshgrid(x,y)
Z = (-d - a*X - b*Y) / c
fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, alpha=0.45)
plt.show()
How can I align two planes and create 3d plot of two align planes in one graph?如何对齐两个平面并在一张图中创建两个对齐平面的 3d plot?
At the end, I want to transform the datapoints on each sides of hyperplanes最后,我想转换超平面两侧的数据点
Each datapoints with hyperplane should looks like following enter image description here每个带有超平面的数据点应该如下所示enter image description here
data points:数据点:
data1 = [[0.190133571624755, 0.146549582481384, 0.391435742378234, 'near'], [0.0154470205307006, 0.0959569215774536, 0.484999418258667, 'near'], [-0.119875073432922, 0.0414541959762573, 0.542818903923034, 'near'],[0.104917883872985, 0.058539867401123, 0.171926498413085, 'far'],[0.177520513534545, 0.130982756614685, 0.0330302715301513, 'far'],[0.246979117393493, 0.173633933067321, 0.373323440551757, 'far']]
data2 = [[0.334545135498046, -0.0318257808685302, 0.282101511955261, 'near'], [0.411889553070068, 0.0223467350006103, 0.183727979660034, 'near'], [0.330880641937255, -0.00959080457687378, 0.178299665451049, 'near'],[-0.00756144523620605, -0.07442307472229, -0.227764248847961, 'far'],[-0.268512785434722, -0.309048891067504, 0.456292867660522, 'far'],[-0.305409669876098, -0.304299354553222, 0.281461238861084, 'far']]
# Create the pandas DataFrame
df1 = pd.DataFrame(data1, columns=['A', 'B', 'C', 'NearOrFar'])
df2 = pd.DataFrame(data2, columns=['A', 'B', 'C', 'NearOrFar'])
If you simply want to plot the two planes on the same 3d axes, then you just need to compute two different values for Z
and plot the two Z
s relative to the same X
s and Y
s, like so:如果你只是想 plot 在相同的 3d 轴上的两个平面,那么你只需要计算两个不同的
Z
值和 plot 两个Z
相对于相同的X
s 和Y
s,像这样:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# first plane:
a1 = -5.297742252442251
b1 = 21.751836101364013
c1 = -2.470896764133499
d1 = -0.5601826186620921
# second plane:
a2 = 45.42557999642176
b2 = -16.9433283673388
c2 = 2.5117971500097287
d2 = -8.528560240570203
x = np.linspace(-1, 1, 100)
y = np.linspace(-1, 1, 100)
X, Y = np.meshgrid(x, y)
Z1 = (-d1 - a1 * X - b1 * Y) / c1
Z2 = (-d2 - a2 * X - b2 * Y) / c2
fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection="3d")
ax.plot_surface(X, Y, Z1, alpha=0.45)
ax.plot_surface(X, Y, Z2, alpha=0.45)
plt.show()
This produces the following figure:这会产生下图:
As to "aligning" the two planes, it's not clear to me what you're asking...?至于“对齐”两架飞机,我不清楚你在问什么......? Two planes will be coplanar if they have the same values of a, b, c and d in the equation you gave above - if they have different values of a, b, c and d, they won't be coplanar.
如果两个平面在您上面给出的等式中具有相同的 a、b、c 和 d 值,则它们将共面 - 如果它们具有不同的 a、b、c 和 d 值,则它们不会共面。 They may intersect, they may not - and to ensure you graph them where they intersect (should they do so), you'd need to determine the values of x and y where they have equal values of z and set your xrange and yrange accordingly.
它们可能相交,也可能不相交——为了确保你在它们相交的地方画出它们(如果它们这样做的话),你需要确定 x 和 y 的值,它们具有相等的 z 值,并相应地设置你的 xrange 和 yrange . If you can explain the meaning of "align" for your particular purposes, perhaps I could expand on this answer to accommodate.
如果您可以为您的特定目的解释“对齐”的含义,也许我可以扩展这个答案以适应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.