• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
andrew111

Calculate if angle between two triangles connected by edge

8 posts in this topic

Hi I have two triangles sharing an edge and I have their normal vectors.







Na          Nb
 \    F    /
  \  /|\  /
   \/ | \/
   /\ | /\
   \  |  /
    \ | /
     \|/
      G

(Na and Nb are the triangle normals, F and G are their shared edge)

I want to check if the angle between the normals is: = 0, < PI, = PI or > PI.

 

I'm a bit rusty on 3d related math, but I looked at dot product and I don't think that works since I believe it can only be used to find the angle between 0 and PI, where as I  want between 0 and 2*PI.

 

I think maybe something could be done with cross product, e.g. since normals are unit length I have:

Na * Nb = sinX*V (V being the cross product, X being the angle).

 

But I don't know where to go from there.

 

 

 

I've looked at this post from a similar/same question: http://www.gamedev.net/topic/112385-detecting-if-2-triangles-are-concave-or-convex/?view=findpost&p=1604381

 


 

 

I presume A and B are supposed to indicate the surface normals? I''ll ut the non-orthogonality of the pictures down to the limitations of ascii art!

There may indeed be an easier method, but here is one answer to your problem. First, impose an ordering of traversal along the edge. Call A the first triangle edge and B the second triangle edge.

1) Compute the tangent vector (T) to B, so that T.NB = 0. Additionally, choose the positive direction for the tangent vector to be away from A (i.e., in the positive traversal direction)

2) Compute the components of the normal NA in the directions of T and NB, so that NA = a1T + a2NB

A is concave if a1 < 0 and convex if a1 > 0.

As I said though, there may be an easier way... I just cannot think of it at this time.

Cheers,

Timkin

 

But in this I don't understand what the a1 and a2 is (I'm guessing something like sinX), or what he means on the second step, compute the components?

 

Thanks.

Edited by CaptainMurphy
0

Share this post


Link to post
Share on other sites

I'm a bit rusty on 3d related math, but I looked at dot product and I don't think that works since I believe it can only be used to find the angle between 0 and PI, where as I want between 0 and 2*PI.

 

I think your best bet is to use the dot product:

 

If they're coplanar (the normals point the same way) the dot product will be 1.0.

If the triangles are 90 degrees to each other, the dot product will be 0.0

If the triangels are folded right over and face each other the dot product will be -1.0

 

You can get the angle by doing acosf of the dot product.

 

The limitation of using the dot product is that you can't work out the direction of the fold. 90 degrees either way looks the same. The trick would be to use some other technique to work out the fold direction. I can't think of a particularly elegant way to calculate the direction: One idea is to take the normal of your first triangle and dot product it with one of the edge directions from your second triangle (just not the shared edge!). The result will be a positive or negative number depending on which direction the fold is.

Edited by C0lumbo
1

Share this post


Link to post
Share on other sites

(Na and Nb are the triangle normals, F and G are their shared edge)
I want to check if the angle between the normals is: = 0, < PI, = PI or > PI.


What's an example where the angle is more than PI?
1

Share this post


Link to post
Share on other sites

 

The limitation of using the dot product is that you can't work out the direction of the fold. 90 degrees either way looks the same. The trick would be to use some other technique to work out the fold direction. I can't think of a particularly elegant way to calculate the direction: One idea is to take the normal of your first triangle and dot product it with one of the edge directions from your second triangle (just not the shared edge!). The result will be a positive or negative number depending on which direction the fold is.

 

 

Yes this was the problem I ran into, I'll give your suggestion a try.

 

What's an example where the angle is more than PI?

 

 

The triangles are part of a 3D mesh, so I'm trying to tell if they are concave or convex, so >= PI is convex and < PI is concave.

 

The vertices are winded clockwise so the triangle normals always on the outer surface of the mesh.

 

EDIT:

 

Ah I just realised what you meant, I've been looking at the problem a bit wrong. I'll have think about this a bit more and get back to you.

Edited by CaptainMurphy
0

Share this post


Link to post
Share on other sites

Okay, after Álvaro's question I realised I was confusing the problem. for two triangles sharing an edge I want to find out whether they are facing away from each other, facing towards each other or laying flat (same normal).

 

So a slight change from  C0lumbo's method, I dot product the normal from the first triangle to the non shared edge of the second triangle, where dotproduct=0 is both triangles laying flat, dotproduct<0 facing away (convex), dotproduct>0 facing towards (concave).

 

Seems like it should work.

1

Share this post


Link to post
Share on other sites
I understand the question now. I think this would work: Take the cross product of the shared edge and the normal to the first triangle, and compute the dot product of that vector with the normal to the second triangle. I believe the sign of the result contains your answer.
1

Share this post


Link to post
Share on other sites

It looks to me like you are both conceptually doing the same thing: getting rid of your angular discrepancy problems with cos(theta) by rotating the problem space.  Alvaro's answer is accomplishing this by explicitly computing the third axis of one of the triangles... whereas CaptainMurphy's answer is getting a vector pointed in the same general direction by simply using one of the edges.

 

These two answers will produce the same (correct) result... at least insofar as they both return positive or negative for the same inputs under an assumption of shared edge GF.  Alvaro's answer doesn't depend on the shared-edge asumption, but under this assumption CaptainMurphy's answer is probably a little faster.

Edited by Thinias
1

Share this post


Link to post
Share on other sites
CaptainMurphy's answer is fine, and a bit faster than mine. The reason for my method is that the description of the problem only provides the two normals and the shared edge FG. If you can only use those ingredients to get your answer, use my method; if you can use other edges, CaptainMurphy's method is better.
1

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  
Followers 0