Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Question regarding dot product of polygon normal and poligon vertex


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 29 June 2013 - 07:11 AM

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



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8430

Like
0Likes
Like

Posted 29 June 2013 - 07:15 AM

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, 29 June 2013 - 07:16 AM.


#3 Paradigm Shifter   Crossbones+   -  Reputation: 5408

Like
0Likes
Like

Posted 29 June 2013 - 07:16 AM

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, 29 June 2013 - 07:19 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#4 frob   Moderators   -  Reputation: 22231

Like
0Likes
Like

Posted 29 June 2013 - 07:38 AM


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, 29 June 2013 - 07:57 AM.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#5 Paradigm Shifter   Crossbones+   -  Reputation: 5408

Like
0Likes
Like

Posted 29 June 2013 - 07:43 AM

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


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#6 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 29 June 2013 - 08:37 AM

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



#7 Brother Bob   Moderators   -  Reputation: 8430

Like
0Likes
Like

Posted 29 June 2013 - 08:46 AM

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.



#8 noatom   Members   -  Reputation: 785

Like
0Likes
Like

Posted 29 June 2013 - 09:51 AM

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



#9 Brother Bob   Moderators   -  Reputation: 8430

Like
0Likes
Like

Posted 29 June 2013 - 10:04 AM

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.



#10 Burnt_Fyr   Members   -  Reputation: 1245

Like
0Likes
Like

Posted 29 June 2013 - 06:29 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS