Advertisement

Abnormal Normals

Started by November 28, 2001 10:17 AM
7 comments, last by Abstract Thought 23 years, 2 months ago
I''ve notice that incorrectly calculated normals can still have a normal appearance. Is there a mathematical way to prove that a set of 3D points all belong to the same normal, other than visually? This how I am calculating my normals... e1 = p1 - p0 e2 = p1 - p2 n = CrossProduct ( e1,e2 ) Normalize ( n ) does p1,p2,p3 == n is p4 != n is p5 != n is p6 != n ... I have a complex data structure, and its a possibility that I have some abnormal normals, due to programers error. I need a way to track these little freaks down, any ideas.
Only by art can we get outside ourselves; instead of seeing only one world, our own, we see it under multiple forms.

> is p4 != n
> is p5 != n
> is p6 != n

The mathod I use to compare two vectors is to work out the sum of squares of the difference between them. E.g. first calculate

v = n - p4

Then work out v.x * v.x + v.y * v.y + v.z * v.z

This is always >= 0. and the bigger the difference between the vectors the bigger it is (it is actualy the square of the length of the difference vector, and many APIs have a function to work it out for you).

In theory it equals zero when the vectors are identical, but this may not always be true due to floating point rounding errors in calculating the vectors. If so don''t test for zero but instad test whether it''s less than the maximum FP error expected.
John BlackburneProgrammer, The Pitbull Syndicate
Advertisement
Thanks johnb, if I understand you correctly, it would go something like this...

e1 = p1 - p0
e2 = p1 - p2
n = CrossProduct ( e1,e2 )
Normalize ( n )

v = n - ( p0 or p1 or p2 )
s = v.x * v.x + v.y * v.y + v.z * v.z
s = 4.9

So p0,p1,p2 should all have the same 's'

v = n - p4
s = v.x * v.x + v.y * v.y + v.z * v.z
s = 4.7

A point outside should have a different 's'

Thanks again




Edited by - Abstract Thought on November 28, 2001 12:29:59 PM
Only by art can we get outside ourselves; instead of seeing only one world, our own, we see it under multiple forms.
Ok, I was wrong...

->So p0,p1,p2 should all have the same ''s''

p0,p1,p2 will only have the same ''s'' if they are the same distance from each other.

?
Only by art can we get outside ourselves; instead of seeing only one world, our own, we see it under multiple forms.
Since normals only include directional information, a dotproduct between 2 normals would be enough to compare them - if the angle between both is small enough (
again, the board screwed up my previous post...

Since normals only include directional information, a dotproduct between 2 normals would be enough to compare them - if the angle between both is small enough then the 2 normals can be considered to be equal.

- AH
Advertisement
Thanks AP, thats what I was looking for.

Ok then, like this...

e1 = p1 - p0
e2 = p1 - p2
n = CrossProduct ( e1, e2 )
Normalize ( n )

d0 = dot ( n, p0 )
d1 = dot ( n, p1 )
d2 = dot ( n, p2 )

d0 == d1 == d2

d3 = dot ( n, p3 )

d3 != ( d0 or d1 or d2 )

One question, would I need to normalize the p's, if they're not unit vectors?

Thats great, AP, I think I can find my abnormal normals now.

Edited by - Abstract Thought on November 28, 2001 2:17:36 PM
Only by art can we get outside ourselves; instead of seeing only one world, our own, we see it under multiple forms.
> One question, would I need to normalize the p''s, if they''re not unit vectors

Yes, you should normalize them or your dotproducts will be denormalized, and you can''t compare them.

- AH
I''m a little lost then AP

This is how I''m testing a triangle strip, this seems to give me what I''m looking for...

i=i+2

e1 = p[i+1] - p[i+0]
e2 = p[i+1] - p[i+2]
n = CrossProduct ( e1, e2 )
Normalize ( n )

d0 = DotProduct ( n, p[i+0] )
d1 = DotProduct ( n, p[i+1] )
d2 = DotProduct ( n, p[i+2] )

print d0,d1,d2

loop

Ouput:

1.248035,1.248035,1.248035
1.318524,1.318524,1.318524
1.339470,1.339470,1.339470
1.304995,1.304995,1.304995
1.224589,1.224589,1.224589
1.116958,1.116958,1.116958
1.000699,1.000699,1.000699
0.889476,0.889476,0.889476

A point from a different plain will have a different value.

>Yes, you should normalize them or your dotproducts will be denormalized, and you can''t compare them.

If I normalize the points before the dotproduct...

i=i+2

e1 = p[i+1] - p[i+0]
e2 = p[i+1] - p[i+2]
n = CrossProduct ( e1, e2 )
Normalize ( n )

n0 = Normalize ( p[i+0] )
n1 = Normalize ( p[i+1] )
n2 = Normalize ( p[i+2] )

d0 = DotProduct ( n, n0 )
d1 = DotProduct ( n, n1 )
d2 = DotProduct ( n, n2 )

print d0,d1,d2

loop

Output:

0.692285,0.832023,0.698129
0.737560,0.821722,0.756332
0.768347,0.791462,0.800923
0.780309,0.742726,0.826098
0.775199,0.682500,0.831800
0.758692,0.619903,0.821581
0.736066,0.562424,0.797955
0.709265,0.514765,0.759785

Am I missing something here?

Thank you, for your help.

I do have a good math book here called "Mastering Technical Mathematics" but it doesn''t cover this area very much.

Xmas wish list for santa...
Only by art can we get outside ourselves; instead of seeing only one world, our own, we see it under multiple forms.

This topic is closed to new replies.

Advertisement