如何从平面方程 ax+by+cz=d 生成矩形?
how to generate rectangle from a plane equation ax+by+cz=d?
给定一个平面方程,如何生成构成矩形的四个点?我只有平面方程ax+by+cz=d。
我正在按照此处列出的方法进行操作 Find Corners of Rectangle, Given Plane equation, height and width
#generate horizontal vector U
temp_normal=np.array([a,b,c])
temp_vertical=np.array([0,0,1])
U=np.cross(temp_normal, temp_vertical)
# for corner 3 and 4
neg_U=np.multiply([-1.0, -1.0, -1.0], U)
#generate vertical vector W
W=np.cross(temp_normal,U)
#for corner 2 and 4
neg_W=np.multiply([-1.0, -1.0, -1.0], W)
#make the four corners
#C1 = P0 + (width / 2) * U + (height / 2) * W
C1=np.sum([centroid,np.multiply(U, width_array),np.multiply(W, height_array)], axis=0)
corner1=C1.tolist()
#C2 = P0 + (width / 2) * U - (height / 2) * W
C2=np.sum([centroid,np.multiply(U, width_array),np.multiply(neg_W, height_array)], axis=0)
corner2=C2.tolist()
#C3 = P0 - (width / 2) * U + (height / 2) * W
C3=np.sum([centroid,np.multiply(neg_U, width_array),np.multiply(W, height_array)], axis=0)
corner3=C3.tolist()
#C4 = P0 - (width / 2) * U - (height / 2) * W
C4=np.sum([centroid,np.multiply(neg_U, width_array),np.multiply(neg_W, height_array)], axis=0)
self.theLw.WriteLine("C4 is " +str(type(C4))+" "+str(C4.tolist()))
corner4=C4.tolist()
corners_list.append([corner1, corner2, corner3, corner4])
使用方程求出该平面内的向量。使用 cross-product (of the first and a normal vector to the plane) 在该平面内找到第二个垂直于第一个的平面。然后将这些向量相加(带+-号,4种可能)生成4个角。
编辑:为您提供更多帮助:
- (a,b,c)为垂直于平面的向量;
- (0,0,d/c), (0,d/b,0) 和 (d/a,0,0) 是属于平面的点,例如b1 = (0,d/b,-d/c)为与平面相切的向量;
两个向量的叉积returns一个垂直于两个向量的向量。所以乘积 b2 = (a,b,c) x (0,d/b,-d/c) 是一个与平面相切的向量,垂直于另一个平面。这样,您就构建了平面 [b1,b2].
的正常基础
从一个点开始,比如说(0,0,d/c),加上b1+b2, b1-b2, -b1+b2, -b1-b2得到4角落.
好的,这是答案:
import numpy as np
a = 2; b = 3; c = 4; d = 5
n = np.array([a,b,c])
x1 = np.array([0,0,d/c])
x2 = np.array([0,d/b,0])
def is_equal(n,m):
return n-m < 1e-10
def is_on_the_plane(v):
return is_equal(v[0]*a + v[1]*b + v[2]*c, d)
assert is_on_the_plane(x1)
assert is_on_the_plane(x2)
# Get the normal basis
b1 = x2 - x1
b2 = np.cross(n, b1)
c1 = x1 + b1 + b2
c2 = x1 + b1 - b2
c3 = x1 - b1 + b2
c4 = x1 - b1 - b2
assert is_on_the_plane(c1)
assert is_on_the_plane(c2)
assert is_on_the_plane(c3)
assert is_on_the_plane(c4)
assert is_equal(np.dot(c1-c3, c1-x2), 0)
assert is_equal(np.dot(c2-c1, c2-c4), 0)
# etc. :
# c3 c1
#
# x1
#
# c4 c2
它实际上是一个正方形,但您肯定可以找到如何将其变成不太具体的矩形。
给定一个平面方程,如何生成构成矩形的四个点?我只有平面方程ax+by+cz=d。
我正在按照此处列出的方法进行操作 Find Corners of Rectangle, Given Plane equation, height and width
#generate horizontal vector U
temp_normal=np.array([a,b,c])
temp_vertical=np.array([0,0,1])
U=np.cross(temp_normal, temp_vertical)
# for corner 3 and 4
neg_U=np.multiply([-1.0, -1.0, -1.0], U)
#generate vertical vector W
W=np.cross(temp_normal,U)
#for corner 2 and 4
neg_W=np.multiply([-1.0, -1.0, -1.0], W)
#make the four corners
#C1 = P0 + (width / 2) * U + (height / 2) * W
C1=np.sum([centroid,np.multiply(U, width_array),np.multiply(W, height_array)], axis=0)
corner1=C1.tolist()
#C2 = P0 + (width / 2) * U - (height / 2) * W
C2=np.sum([centroid,np.multiply(U, width_array),np.multiply(neg_W, height_array)], axis=0)
corner2=C2.tolist()
#C3 = P0 - (width / 2) * U + (height / 2) * W
C3=np.sum([centroid,np.multiply(neg_U, width_array),np.multiply(W, height_array)], axis=0)
corner3=C3.tolist()
#C4 = P0 - (width / 2) * U - (height / 2) * W
C4=np.sum([centroid,np.multiply(neg_U, width_array),np.multiply(neg_W, height_array)], axis=0)
self.theLw.WriteLine("C4 is " +str(type(C4))+" "+str(C4.tolist()))
corner4=C4.tolist()
corners_list.append([corner1, corner2, corner3, corner4])
使用方程求出该平面内的向量。使用 cross-product (of the first and a normal vector to the plane) 在该平面内找到第二个垂直于第一个的平面。然后将这些向量相加(带+-号,4种可能)生成4个角。
编辑:为您提供更多帮助:
- (a,b,c)为垂直于平面的向量;
- (0,0,d/c), (0,d/b,0) 和 (d/a,0,0) 是属于平面的点,例如b1 = (0,d/b,-d/c)为与平面相切的向量;
两个向量的叉积returns一个垂直于两个向量的向量。所以乘积 b2 = (a,b,c) x (0,d/b,-d/c) 是一个与平面相切的向量,垂直于另一个平面。这样,您就构建了平面 [b1,b2].
的正常基础
从一个点开始,比如说(0,0,d/c),加上b1+b2, b1-b2, -b1+b2, -b1-b2得到4角落.
好的,这是答案:
import numpy as np
a = 2; b = 3; c = 4; d = 5
n = np.array([a,b,c])
x1 = np.array([0,0,d/c])
x2 = np.array([0,d/b,0])
def is_equal(n,m):
return n-m < 1e-10
def is_on_the_plane(v):
return is_equal(v[0]*a + v[1]*b + v[2]*c, d)
assert is_on_the_plane(x1)
assert is_on_the_plane(x2)
# Get the normal basis
b1 = x2 - x1
b2 = np.cross(n, b1)
c1 = x1 + b1 + b2
c2 = x1 + b1 - b2
c3 = x1 - b1 + b2
c4 = x1 - b1 - b2
assert is_on_the_plane(c1)
assert is_on_the_plane(c2)
assert is_on_the_plane(c3)
assert is_on_the_plane(c4)
assert is_equal(np.dot(c1-c3, c1-x2), 0)
assert is_equal(np.dot(c2-c1, c2-c4), 0)
# etc. :
# c3 c1
#
# x1
#
# c4 c2
它实际上是一个正方形,但您肯定可以找到如何将其变成不太具体的矩形。