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

Archived

This topic is now archived and is closed to further replies.

RZ

How to find out if two triangles touch each other..

9 posts in this topic

I''m trying to find out if two triangles touch each other..Not intersects.. just touch. In other words if any vertices of one triangles lie on the edge of the other triangle. Does anyone know how to solve this? Thanks!
0

Share this post


Link to post
Share on other sites
You''re trying to find out if a point (vertex) on one triangle is on the line (edge) of another triangle. Which is a case of finding the equation of the line and testing whether the point p in question satisfies it.

I can''t remember the equations in question, but someone else is sure to. (Sorry, I just moved).
0

Share this post


Link to post
Share on other sites
Let''s say point P is a vertex on the 1st triangle and has coords (xP, yP, zP). Let''s then also say that Q and R make up a side of the 2nd triangle and have coords (xQ, yQ, zQ) and (xR, yR, zR) respectively.

Point P is on Line QR (therefore making the triangles touch) iff

xP - xQ, yP - yQ, zP - zQ is in proportion to xR - xQ, yR - yQ, zR - zQ, iff

  
xP - xQ yP - yQ zP - zQ
------- == ------- == -------
xR - xQ yR - yQ zR - zQ


(You only need to test two of the three equalities in the thing above. )

Dragonus
Thought of the Moment
If F = ma, and Work = Fd, then does Work = mad?
0

Share this post


Link to post
Share on other sites
In 3d...

I''ve looked around on the web and in my math books but I have not found any good solution..
On way to find if a point lies on a line(3D) is this:

(x - x0) / Vx = (y – y0) / Vy = (z - z0) / Vz

(x0,y0,z0) is a point on the line.
(Vx,Vy,Vz) is an vector on the line.

Then you put a point (x,y,z) in the equation to see if it is on the line.
The problem is that this only works if Vx,Vy,Vz != 0
so that equation doesn’t work in my case…

Sorry my english isn’t that good…hope you understand anyway..

0

Share this post


Link to post
Share on other sites
Hi Dragonus

Didn’t see your post before I had posted mine, the AP.. forgot to type username..
Your equation is the same as mine.. but as I said it will not work if the edge vectors x, y or z = 0
There must be another way
0

Share this post


Link to post
Share on other sites
It''s mathematically tricky to test for exact properties such as a point lying exactly on a line because of limitations of mathematical precision. It''s better to test for closeness within a tolerance, e.g. testing whether a corner of one triangle is within 1/1000 of the edge of the other. I.e. work out the distances and see if any are small enough, so you need a way to work out the smallest distance from the corners of one triangle to the edges of another.

You can do this by looking at each corner and edge in turn. E.g. take one corner of one triangle, P, and an edge of the other, AB. You want the distance from P to AB.

AB can be describd using a line equation,

X = A + t * (B - A)

Where A and B are the ends of the line and t is a scalar which goes from 0 to 1 as the line is traversed from A to B.

From this and the point P the point on AB nearest to P is given by

t = ((P - A) . (B - A)) / ((B - A) . (B - A))

Where ''.'' is the inner product.

The result depends on the value of t, but because t is restricted to a range of 0 to 1:
If t < 0 the nearest point on the line is when t = 0, at A, so the distance is the distance from A to P
If t > 1 the nearest point on the line is when t = 1, at B, so the distance is the distance from B to P
Otherwise the nearest point is between A and B. Work this point out by putting t into

X = A + t * (B - A)

And the distance is the distance from X to P.

Then work this out for all corners and all the edges of the triangles: a lot more calculations but easy enough to work out in for () loops. Each time work out the distance, and if it''s shorter than the shortest worked out distance remember it. When you have done all edges and corners the triangles ''touch'' if the distance is short enough.

This works in 2D and 3D, even for triangles (or other polygons) not parallel to each other. It is very calculation intensive so is not recommended for large groups of triangles/polygons, unless other logic takes care of making sure only adjacent polys are tested.
0

Share this post


Link to post
Share on other sites
quote:
Original post by RZ
Your equation is the same as mine.. but as I said it will not work if the edge vectors x, y or z = 0
There must be another way



Don''t worry about that ^_~

Anyways, about the zero thing, for mine it will work... most of the way. We only have a problem if any of the x-, y-, or z-coordinates of Q equals exactly the corresponding coordinate of R. If that''s the case (say, xQ == xR) then xP == xQ (== xR) must be true for it to work. Then you have to test the final euqation to make sure the ratios work.

If you have two of the denominators at 0 (say, xQ == xR && yQ == yR) then test xP == xQ (== xR) and yP == yQ (== yR) and then the z-coordinate is trivial.

If you have three denominators at 0, then we don''t really care because the Q == R in 3-space. Then, P is guaranteed to be colinear with Q & R because, as well all know, a line is determined by two points...

As far as the tolerance, granted I was doing this hypothetically. Knowing FPU''s and whatnot, it won''t be 100% accurate (e.g., 3 / 2 = 1.49999999 for "stupid" computers). The cheap way to fix that is to (depending upon the order of magnitude of the numbers) multiply them by a power of 10, cast them as int''s, and then test them.

Dragonus
Thought of the Moment
If F = ma, and Work = Fd, then does Work = mad?
0

Share this post


Link to post
Share on other sites
Look at the triangles from two axis (sp?) in 2D, disreguarding the third axis.

if for both of them a trangle created by the midpoints of the lines between corrosponding corners of the two triangles has any of its edges intersecting an edge from one of the two triangles, then the two triangles intersect.
0

Share this post


Link to post
Share on other sites