如何从平面方程ax +生成矩形+ + cz = d?

时间:2016-04-24 19:49:00

标签: python geometry plane

给定平面方程,如何生成包含矩形的四个点?我只有平面方程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])

1 个答案:

答案 0 :(得分:1)

使用等式在该平面内找到一个向量。使用cross-product(第一个和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)是与平面相切的矢量;
  • 两个向量的叉积返回一个垂直于两者的向量。因此,乘积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

它实际上是一个正方形,但你肯定能找到如何使它成为一个不太具体的矩形。