# Question regarding dot product of polygon normal and poligon vertex

This topic is 1668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites

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 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.

##### Share on other sites

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 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 on other sites

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:

What I think happens is:

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

##### Share on other sites

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 on other sites

You ment the inverse of the normal and the blue line right?

##### Share on other sites

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 on other sites

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.