2016-04-24 2 views
0

étant donné une équation plane, comment pouvez-vous générer quatre points qui composent un rectangle? Je n'ai que l'équation plane ax + de + cz = d.comment générer un rectangle à partir d'une équation plane ax + de + cz = d?

Je suivais l'approche énumérés ici 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]) 

Répondre

1

Trouver un vecteur dans ce plan en utilisant l'équation. Trouver un deuxième à l'intérieur de ce plan, perpendiculaire à la première, en utilisant le cross-product (du premier et un normal vector to the plane). Ajoutez ensuite ces vecteurs (avec + - signes, 4 possibilités) pour générer 4 coins.

Modifier: vous aider un peu plus:

  • (a, b, c) est le vecteur normal au plan;
  • (0,0, d/c), (0, d/b, 0) et (d/a, 0,0) sont des points appartenant au plan, c'est-à-dire par exemple b1 = (0, d/b , -d/c) est un vecteur tangent au plan;
  • Le produit croisé de deux vecteurs renvoie un vecteur qui est perpendiculaire aux deux. Donc le produit b2 = (a, b, c) x (0, d/b, -d/c) est un vecteur tangent au plan, perpendiculaire à l'autre. Avec cela, vous avez construit une base normale de l'avion [b1, b2]. Commencez par un point, disons (0,0, d/c), et ajoutez b1 + b2, b1-b2, -b1 + b2, -b1-b2 pour avoir 4 coins.

Ok voici la réponse:

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 

Il est en fait un carré, mais vous pouvez sûrement savoir comment en faire un rectangle moins spécifique.

+0

si je comprends bien trouver un vecteur U dans le plan. trouver V = np.cross (U, N) où N = np.array ([a, b, c]) puis trouver 4 coins où coin = np.add (+/- V, +/- U) – webmaker

+0

des points (x, y, z) dont les coordonnées vérifient l'équation du plan définissent un tel vecteur. – JulienD

+0

comment puis-je trouver ce premier vecteur dans un plan autre que de brancher arbitrairement des points? – webmaker