text: # Convert norms to plane equations
  
  ## Main Question or Discussion Point
  
  Hello people,
  
  I have a file that contains planes in the form of norms that have lengths (magnitude not always 1). The file looks like this:
  
  A1 B1 C1
  A2 B2 C2
  A3 B3 C3
  ...
  
  Every A B C define the components of a norm to a plane. These sets of planes form a polyhedron. I'm trying to find a way to convert every 3 components of the norms to a plane equation of the form:
  
  ax + by + cz = d
  
  The problem arises when trying to define d, where a, b and c are obviously equal to A, B and C respectively. The problem is there because the norm defines the direction of the plane being perpendicular to a vector from the origin to the plane. While d defines the distance from the origin in the z axis direction.
  
  As a try I defined d to be positive or negative by the sign of C, because this defines whether the slope of the plane on the xy-plane is positive or negative, and the value of d is the magnitude of the vector (A,B,C), because I think the distance in the z axis is this magnitude. So:
  
  d = Sign(C)*sqrt(A^2+B^2+C^2)
  
  This definition for the plane does not give the right shape when redrawing the polyhedra.
  
  Have I thought in the right way? any ideas?
  
  Could anyone tell me how to define d in the right way? or maybe if there's a different definition for a,b,c other than what I've given.
  
  Thank you
  
  Redbelly98
  Staff Emeritus
  Homework Helper
  d is not uniquely determined with the given information, so your problem is not solvable as given. A, B, and C determine an infinite set of parallel planes. To get d, you need to know something else about the plane, for example the coordinates of one point in the plane.
  
  Actually this would be the case if the vectors are totally norms, but this is not the case. The norms magnitudes are not always 1, so we can say that the norm contains the distance from the origin (the distance of a point perpendicular to a vector from the origin, or in other words the closest point to the origin). Doesn't this suffice?
  Actually this explanation for the norms is what I found, because some of them have the value 1, and others a little bit more, the thing that defines the scaling of this polyhedron somewhat.
  
  Thank you
  
  Mark44
  Mentor
  Please help me understand what A1 B1 C1 represent. Are these the coordinates of a vector from the origin to a point (A1, B1, C1)? And are they also the components of a vector that is normal to a plane?
  
  Supposing this is right, and with a triple of 3 1 2, you have a plane whose normal is <3, 1, 2> that contains the point (3, 1, 2). The equation of this plane is 3(x - 3) + 1(y - 1) + 2(z - 2) = 0, or 3x + y + 2z = 14.
  
  Let me know if I'm off-track here.
  
  I tried to implement this, and when generalising this to any possible vector a,b,c I get the following:
  
  a(x-a)+b(y-b)+c(z-c)=0
  ax+by+cz=a^2+b^2+c^2
  Which does not give the right shape for the polyhedra, and d is always positive which doesn't make sense.
  
  I'm gonna try to explain the way those planes are used, hopefully this would make things clearer. Because I think I'm misunderstanding the whole thing...
  
  First, here's an 18 planes polyhedron as an example:
  0.9959536 7.9041690E-02 -4.2764984E-02
  0.8761591 -1.4950413E-02 -0.4817901
  0.8869783 -5.5180021E-02 0.4585026
  -0.9978907 1.9839464E-02 6.1809473E-02
  -0.8442029 5.7796936E-02 0.5328986
  -0.8443919 7.1644172E-02 -0.5309137
  -1.8898658E-02 1.380071 -5.3281873E-02
  -0.5947330 1.223505 -7.9500914E-02
  0.6290656 1.191396 9.9840704E-03
  -0.1006644 -1.388037 -0.1081614
  0.7158133 -1.133777 5.6229603E-02
  -0.7008358 -1.191331 -5.7600696E-02
  6.2555380E-02 1.5256885E-02 0.9979249
  -2.8316367E-02 -0.4841180 0.8745444
  2.7606569E-02 0.5129365 0.8579826
  -4.2303033E-02 -6.7472480E-02 -0.9968239
  -2.0625610E-02 0.4322402 -0.9015226
  -1.5496802E-04 -0.5653075 -0.8248802
  
  In a 3D grid of points, the job is to find whether every point lies inside this polyhedron or outside, meaning before or after every plane defined with these vectors. What this guy does to perform this check is the following: for the vector A, and a point defined with the vector R, he does the following:
  
  A(R-A) = k (results some scalar)
  So this is a dot product of A with it subtracted from R, I tried to understand why he does this, and eventually, after graphing, I found that the angle between A and (R-A) is gonna be greater than 90 degrees if the point lies after the plane, and vice versa. So this check tells us whether the point is in or out by knowing the sign of this product (sign if k).
  
  I want to optimise this program because it's not so clever to redo this check for every point, but I need to convert this representation of vectors to the former mentioned planes representation.
  
  Any ideas?
  
  Thank you!
  
  Redbelly98
  Staff Emeritus
  Homework Helper
  Actually this would be the case if the vectors are totally norms, but this is not the case. The norms magnitudes are not always 1, so we can say that the norm contains the distance from the origin (the distance of a point perpendicular to a vector from the origin, or in other words the closest point to the origin). Doesn't this suffice?
  A normal vector does not necessarily have to have magnitude 1 (that would be a unit normal), it just needs to specify a direction. You cannot say these vectors represent the distance from the origin just because they don't have a magnitude of 1. Do you have any other information? Is it explicitly said, somewhere, that these vectors also represent displacement from the origin to the plane?
  
  Actually this explanation for the norms is what I found, because some of them have the value 1, and others a little bit more, the thing that defines the scaling of this polyhedron somewhat.
  
  Thank you
  What explanation? Could you post any other information, word-for-word, that you have concerning this? Otherwise we are just guessing here.
  I tried to implement this, and when generalising this to any possible vector a,b,c I get the following:
  
  a(x-a)+b(y-b)+c(z-c)=0
  ax+by+cz=a^2+b^2+c^2
  Which does not give the right shape for the polyhedra, and d is always positive which doesn't make sense.
  Those are two equivalent equations for a plane that both contains the point (a,b,c) and has a normal in the direction (a,b,c). Note that if a,b,c were all negative, you would likely multiply the second equation by -1 to get a negative d.
  
  I'm gonna try to explain the way those planes are used, hopefully this would make things clearer. Because I think I'm misunderstanding the whole thing...
  
  First, here's an 18 planes polyhedron as an example:
  0.9959536 7.9041690E-02 -4.2764984E-02
  0.8761591 -1.4950413E-02 -0.4817901
  0.8869783 -5.5180021E-02 0.4585026
  -0.9978907 1.9839464E-02 6.1809473E-02
  -0.8442029 5.7796936E-02 0.5328986
  -0.8443919 7.1644172E-02 -0.5309137
  -1.8898658E-02 1.380071 -5.3281873E-02
  -0.5947330 1.223505 -7.9500914E-02
  0.6290656 1.191396 9.9840704E-03
  -0.1006644 -1.388037 -0.1081614
  0.7158133 -1.133777 5.6229603E-02
  -0.7008358 -1.191331 -5.7600696E-02
  6.2555380E-02 1.5256885E-02 0.9979249
  -2.8316367E-02 -0.4841180 0.8745444
  2.7606569E-02 0.5129365 0.8579826
  -4.2303033E-02 -6.7472480E-02 -0.9968239
  -2.0625610E-02 0.4322402 -0.9015226
  -1.5496802E-04 -0.5653075 -0.8248802
  
  In a 3D grid of points, the job is to find whether every point lies inside this polyhedron or outside, meaning before or after every plane defined with these vectors. What this guy does to perform this check is the following: for the vector A, and a point defined with the vector R, he does the following:
  
  A(R-A) = k (results some scalar)
  So this is a dot product of A with it subtracted from R, I tried to understand why he does this, and eventually, after graphing, I found that the angle between A and (R-A) is gonna be greater than 90 degrees if the point lies after the plane, and vice versa. So this check tells us whether the point is in or out by knowing the sign of this product (sign if k).
  
  I want to optimise this program because it's not so clever to redo this check for every point, but I need to convert this representation of vectors to the former mentioned planes representation.
  
  Any ideas?
  
  Thank you!
  Okay, that is consistent with the assumption that the plane must contain the point (a,b,c) as well as having a normal in the direction (a,b,c). And a negative value for k indicates that R is on the same side of the plane as the origin, (I think you would say R is before the plane, not after it, in that case).
  
  Two questions for you:
  
  1. Who is "this guy" that you refer to? It sounds like he would be a good person to ask!
  
  2. Do we know for a fact that the origin lies within the polyhedron? That must be true for the above approach to work. If the origin is not within the polyhedron, things become more complicated.
  
  Oh! I thought norms should always carry the value one, but ... thanks for that piece of information ;). In other words I can say that this is a norm that contains a length, and all lengths have to scale with each other, so there's no absolute length in the problem.
  I meant with the explanation for the norms that their magnitude isn't always one.
  
  This guy is a former postdoc student and he left to india, and asking him is something not possible unfortunately :(
  
  Yes the origin lies inside the polyhedron, this is a given.
  
  a(x-a)+b(y-b)+c(z-c)=0
  ax+by+cz=a^2+b^2+c^2
  
  Of course they are equivalent! I just rearranged the former to get latter, but I meant that the sign of d is not determined systematically! I don't have a way to determine it! is it the sign of c? that was my first assumption but failed! Maybe finding the right way to set the sign for d is the solution to this problem.
  
  Any ideas about the sign of d?
  
  Thank you!
  
  Mark44
  Mentor
  d = a^2 + b^2 + c^2, right? If so, d will always be >= 0, regardless of the signs of a, b, and c.
  
  The sign means so much actually. Imagine we have a cube you'll have 2 equal d's for every plane equation in this case, and the only distinguishing method would be the sign, so 3 positive d's, and 3 negative.
  
  Right?
  
  Redbelly98
  Staff Emeritus
  Homework Helper
  Any plane can be represented using a positive d, so this is not a restriction or problem whatsoever.
  
  Example:
  x + y + z = -1​
  is the same as
  -x - y - z = +1.​
  
  Actually what's really surprising, is that using the form d=a^2+b^2+c^2 makes a lot of sense because we may say that the signs of a,b and c will implicitly take care of the sign of d, but it doesn't give the right shapes for the polyhedra! I'm getting some elongated shapes that make no sense, and they're elongated in one direction, like 1 unit in -z and 15 units in +z. Which doesn't make sense at all, because the polyhedra are somehow symmetric (not exactly), symmetric in the sense of their center...
  
  Any ideas about how to detect the problem?
  
  Mark44
  Mentor
  TheDestroyer said:
  Actually what's really surprising, is that using the form d=a^2+b^2+c^2 makes a lot of sense because we may say that the signs of a,b and c will implicitly take care of the sign of d,...
  It doesn't matter what the signs of a, b, and c are. d >= 0 regardless of the signs of a, b, and c.
  
  Yes, that's what I meant. So if you have 2 parallel planes for a cube, you'd get the following:
  
  In vector representation:
  A,B,C=1,0,0
  A,B,C=-1,0,0
  
  And so when we convert these to planes equations:
  
  x = 1
  -x = 1 -> x = -1
  
  This is what I meant by the sign being implicit.
  
  This makes sense when talking about a simple planes, but when using complicated polyhedra and planes, it gives results that don't make sense, the elongated stuff I talked about...
  
  Any ideas how to start thinking of this problem?
  
  Thank you guys for every moment you're wasting with me :)
  
  Redbelly98
  Staff Emeritus