Sign in to follow this  
noatom

Question regarding dot product of polygon normal and poligon vertex

Recommended Posts

noatom    927

I know that you can find it a polygon is facing the camera using that method.You need the polygon normal and the position of a vertex on that polygon.I don't remember more.

 

Can someone explain with details,and maybe some drawings?

 

Thanks

Share this post


Link to post
Share on other sites
Brother Bob    10344

You take the dot product of the normal and the vector between the viewpoint and one of the vertices. A negative dot product means the side of the polygon in the direction of the normal is visible from the view point.

Edited by Brother Bob

Share this post


Link to post
Share on other sites

If you do the dot product of the normal and the vector from the camera to a point on the polygon it will be negative if they are facing in opposite directions, which means the polygon is facing the camera.

 

Dot product positive -> vectors are facing same direction (within 90 degrees each way)

Dot product negative -> vectors facing different directions

Dot product 0 -> vectors are perpendicular

 

You can also use the z-component of the cross product of polygon edge directions in screen space to check if the polygon is back facing.

 

EDIT: My first answer was incorrect, edited now.

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites
frob    44911

I know that you can find it a polygon is facing the camera using that method.  Can someone explain with details,and maybe some drawings?

There are several formulas to define a dot product, just like there are several formulas that can define a line.

 

One of those formulas is:

 

DotProduct = |A| * |B| * cos(AngleBetweenAB)

 

The dot product equals the magnitude (length) of the first vector, times the magnitude of the second vector, times the cosine of the angle between the two vectors.

 

If both vectors are normalized (length = 1) they drop out of the equation.

 

So if we have normalized vectors A and B: DotProduct = cos(AngleBetweenAB).

 

If you remember from the definition of a cosine, angles between -90 degrees and 90 degrees are all positive, with 90 and -90 being exactly zero.

 

 

So if one vector is pointing forward and the dot product is positive, the second vector is also pointing forward.  It might only be a tiny bit forward, but it is still at least partially forward.

 

The opposite is also true: if one vector is pointing forward and the dot product is negative, the second vector is pointing backwards.  It might only be a tiny bit backward, but it is still at least partially backward.

 

 

And since for the normalized angles DotProduct = cos(AngleBetweenAB), that means you can undo the cosine:  AngleBetweenAB = arccos(DotProduct)

 

Sorry no pictures, but I hope that clears it up.

Edited by frob

Share this post


Link to post
Share on other sites

If you are just testing relative facing (towards/away from/perpendicular) you don't need to normalise, all that matters is the sign (+ve -> facing same way, -ve -> facing opposite way, 0 -> perp).

Share this post


Link to post
Share on other sites
noatom    927

Ok,got it:

If you are just testing relative facing (towards/away from/perpendicular) you don't need to normalise, all that matters is the sign (+ve -> facing same way, -ve -> facing opposite way, 0 -> perp)

 

But I still have problems visualizing the test.For example:

 

x4irmg.png

 

 

 

 

What I think happens is:

 

2v86ez4.png

 

 

 

Obviously,my thoughts are wrong,but can someone say where and why? Thanks

Share this post


Link to post
Share on other sites
Brother Bob    10344

The angles you measure in for the two polygons have different references. Notice how on the left side the angle is measured between the normal and the red line, while on the right hand side the angle is measured between the inverse of the normal and the red line.

Share this post


Link to post
Share on other sites
Brother Bob    10344

The angle is between the blue line and the red line. I thought the blue line was the extended normal from the origin since that is what you measured the angle from and not the black line itself. What are the red and blue lines then in your picture, just to make sure we're talking about the same thing.

Share this post


Link to post
Share on other sites
Burnt_Fyr    1665

Your angle measurement is a misinterpretation. Think of the vectors as free vectors, not localized.Now imagine both vectors(the normal and the camera to vertex vector) with their tails attached. The polygon on the left has a normal pointing away from the blue vector. If you do the same on the right, you can see they point the same direction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this