-3

I have three points

P0=[x0,y0,z0] 
P1=[x1,y1,z1] 
P2=[x2,y2,z2] 

and I want to calculate the normal out of them. What I did is:

normal = cross(P0-P1, P0-P2); 

and then I wanted to plot the normal so what I did is,

c = normal + P0 %end position of normal vector
quiver3(P0(1), P0(2), P0(3), c(1), c(2), c(3));

but it didn't work (It looks like there is an angle between the line and the plane. So it is not the normal).

Any suggestions please?

Jack_111
  • 881
  • 5
  • 14
  • 26
  • 2
    what do you mean by "did not work"? I suggest you add an example: the values of `P0`, `P1` and `P1` and a screen shot of your `quiever3` output. – Shai Jul 30 '13 at 14:42
  • Might be helpful: http://stackoverflow.com/questions/2035659/normal-vector-of-three-points – amustafa Jul 30 '13 at 14:43
  • Full code might help us help you, as well as the content of your workspace. What "didn't work" means btw ? Did you get an error ? – CTZStef Jul 30 '13 at 14:45

1 Answers1

6

"It has an angle so it is not the normal" . There are two problems.

First problem - you misinterpret how the quiver3 command works. The first three elements are the start of the quiver (the back of the arrow), but the next three are not the endpoint (your normal + P0) - they are the direction. So I think you need to change your code to

normal = cross(P0-P1, P0-P2);
normal = normal / norm( normal ); % just to make it unit length
figure
quiver3(P0(1), P0(2), P0(3), normal(1), normal(2), normal(3));
axis equal

You can confirm a vector is normal to your plane by confirming that the dot product is zero:

disp(dot((P0 - P1, normal));
disp(dot((P0 - P2, normal));

You would expect the result to be a "number very close to zero" - rounding error will usually prevent things from being exactly zero (consider any value less than 1e-16 smaller than the length of the vectors to be "zero").

Floris
  • 45,857
  • 6
  • 70
  • 122
  • 1
    the dotprodut is not zero it is -1.084202172485504e-019 – Jack_111 Jul 30 '13 at 15:08
  • 1
    Good! That's "zero to within rounding error". It is -0.000000000000000000108 . Close enough for almost anything. How do things look when you set the axes to `equal`? – Floris Jul 30 '13 at 15:13