Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am calculating the normal vector to a plane ax+by+cz+d=0

According to the book:

The normal vector N is often normalized to unit length because in that case the equation

d = N ⋅Q + D 

gives the signed distance from the plane to an arbitrary point Q. If d = 0, then the point Q lies in the plane. If d > 0, we say that the point Q lies on the positive side of the plane since Q would be on the side in which the normal vector points.

How to get the N (Normal vector)? Thank you

share|improve this question
8  
You don't appear to have made a lot of research first, did you? –  Sam Hocevar Apr 21 '12 at 10:51
add comment

1 Answer

From MathWorld:

Given the plane

enter image description here

Then the normal vector is

enter image description here

The normal unit vector n is given by:

enter image description here

Therefore, for the plane 5x+2y+3z-1=0,

The normal vector N is

N = [5,2,3]

The magnitude |N| is

|N| = sqrt(5^2 + 2^2 + 3^2)

|N| = 6.1644

The normal unit vector n is therefore approximately:

n = N / |N|

n = [0.8111, 0.3244, 0.4866]

which you can check by measuring the length of n.

Code:

import math

def mag(V):
  return math.sqrt(sum([x*x for x in V]))
def n(V):
  v_m = mag(V)
  return [ vi/v_m for vi in V]

In an interactive python shell:

>>> N = [5,2,3]
>>> mag(N)
6.164414002968976
>>> n(N)
[0.8111071056538127, 0.3244428422615251, 0.48666426339228763]
>>> mag(n(N))
1.0
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.