View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Parametric Triangle Representation

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.

3 replies to this topic

### #1deanmat  Members

Posted 15 May 2000 - 04:53 PM

I know this is simple, but I''m having a brain meltdown right now...I''ve looked through all my books I have and can''t seem to find anything regarding parametric representation of triangles. I''ve done a Ray-Triangle intersection test. As a result of a successful intersection, I end up with U & V coordinates for the triangle. Here is my question... How do I compute the X,Y,Z coordinates of the intersection based upon the U & V coordinates? Here is what I''ve done so far. It "feels" correct, but something about the results don''t seem to work 100% of the time V = Triangle Vertex P = Intersection Point Edge1=V1-V0; Edge2=V2-V0; P=V0+Edge1*U+Edge2*V Any pointers will be greatly appreciated. Dean M.

### #2goltrpoat  Members

Posted 15 May 2000 - 05:22 PM

ok.. for ray-triangle intersection (or ray-anything intersection ) it''s easier to work with the Q(t)=Q+vt form, all you have to do is plug that into the plane equation, get the intersection point at Q+vt for the given t and then find out if the intersection point is within the triangle.

i don''t really understand what you mean by "U & V coordinates for the triangle".. are those supposed to be 2d coordinates in the triangle''s plane, or is U an offset along two edges with V being a distance along the resulting vector, or what?

-goltrpoat

--
Float like a butterfly, bite like a crocodile.

### #3Andreas Jonsson  Moderators

Posted 15 May 2000 - 10:57 PM

The u,v coordinates that you are getting from the intersection are called barycentric coordinates. The x,y,z coordinates are computed with:

P = (1-u-v)*V0 + u*V1 + v*V2

This just happens to be what you have already figured out, just a little rearrangement of the terms.

With the barycentric coordinates it is real easy to test if the point is within the triangle. For the point to be within the following conditions must hold:

u >= 0
v >= 0
u+v <= 1

- WitchLord

### #4deanmat  Members

Posted 16 May 2000 - 05:57 PM

Thanks for the help...I updated my code with the correct way to determine the intersection point and I am up and going.

I''m going to have to do some reading up on barycentric coordinates. I''ve seen that term thrown around, but haven''t yet taken the time to actually understand what it is.

If you are curious: I am writing a sort of level editor (non-gaming related, eventually I get around to writing games). It is for architectural walkthroughs. But, game technologies and techniques are exactly what this project calls for.

With this piece of information (the intersection point), I now have 100% accurate polygon selection with the mouse working. I''m able to determine the polygon with the closest intersection point to the camera and highlight it for the user to do something. It is really quite pleasing to see this work perfectly.