# A 2d TriArea method,don't understand why,need help

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

## Recommended Posts

hi,again another geometry silly question to ask if i may.

i'm a total math idiot,i read this book named Realtime Collision Detection,and

there is a function called TriArea2D defines below

 inline float TriArea2D(float x1, float y1, float x2, float y2, float x3, float y3) { return (x1-x2)*(y2-y3) - (x2-x3)*(y1-y2); } // Compute barycentric coordinates (u, v, w) for // point p with respect to triangle (a, b, c) void Barycentric(Point a, Point b, Point c, Point p, float &u, float &v, float &w) { // Unnormalized triangle normal Vector m = Cross(b - a, c - a); // Nominators and one-over-denominator for u and v ratios float nu, nv, ood; // Absolute components for determining projection plane float x = Abs(m.x), y = Abs(m.y), z = Abs(m.z); // Compute areas in plane of largest projection if (x >= y && x >= z) { // x is largest, project to the yz plane nu = TriArea2D(p.y, p.z, b.y, b.z, c.y, c.z); // Area of PBC in yz plane nv = TriArea2D(p.y, p.z, c.y, c.z, a.y, a.z); // Area of PCA in yz plane ood = 1.0f / m.x; // 1/(2*area of ABC in yz plane) } else if (y >= x && y >= z) { // y is largest, project to the xz plane nu = TriArea2D(p.x, p.z, b.x, b.z, c.x, c.z); nv = TriArea2D(p.x, p.z, c.x, c.z, a.x, a.z); ood = 1.0f / -m.y; } else { // z is largest, project to the xy plane nu = TriArea2D(p.x, p.y, b.x, b.y, c.x, c.y); nv = TriArea2D(p.x, p.y, c.x, c.y, a.x, a.y); ood = 1.0f / m.z; } u = nu * ood; v = nv * ood; w = 1.0f - u - v; } 

i don't understand why this function can calculate TriArea,i only know if two vector cross product,you get a parallelogram area in 2D case,right?

but why this called TriArea??Do i misread something? Edited by tracegame

##### Share on other sites
Unless I'm missing something obvious, the code has to divide the result by two in order to get the area of triangle. As it is, it does indeed calculate the cross product, or equivalently the area of the parallelogram spanned by two edges of the triangle, and not the area of the triangle itself.

##### Share on other sites
What's it used for? Even if it does not compute the actual area of a triangle, it may still be used for comparing triangle areas for sorting or whatever.

##### Share on other sites
oops,it's my fault,update the full code,sorry.

and i agree with Bob,it should be divided by two,and i'm NOT good at english,

so maybe i don't fully understand TriArea2D mean,does it also mean some ratio of Area,or something like that?

or maybe the author writes this name for some short case or use or something,anyway i'm confused with this function name and use.

actually i can not visualize the projection area,and how does it work. Edited by tracegame

##### Share on other sites
I'm at the same point of the same book, and it is pretty confusing. Especially since there is no explanation of the code.

He did explain prior to this that the barycentric coordinates of a point P in triangle ABC are given as,

u = SignedArea(PBC)/SignedArea(ABC),
v = SignedArea(PCA)/SignedArea(ABC), and
w = SignedArea(PAB)/SignedArea(ABC) = 1 - u – v.

He says that instead of computing areas from 3d coordinates of the triangle, we can project vertices onto the yz, zx or xy plane, selecting the plane with largest projected area.

And in the section before Barycentric coordinates, he also says that for a triangle ABC,

d = Cross(B-A, C-A),

where each component of d holds twice the signed area of the projection of ABC onto the yz, zx and xy planes, respectively.

What's happening here is instead of u = SignedArea(PBC)/SignedArea(ProjectionZY(ABC)), it is u = (2*SignedArea(PBC)/(2*SignedArea(ProjectionZY(ABC))). He simply finds the projection with largest projected area, and then finds the Barycentric coordinates using that.

What I don't understand is why he had to multiply the signed area of projection onto the zx plane with -1.

Why does he use ood = 0.01f/-m.y instead of ood = 0.01f/m.y, like the other two planes? There is nothing mentioned related to that in the book.

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 17
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632148
• Total Posts
3004359

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!