Jump to content
  • Advertisement

Archived

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

BrianH

area of an arbitrary triangle

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering how to compute the area of an arbitrary triangle in 3D space, knowing the coordinates of the 3 vertices. I know I should probably remember this, but I just can''t for some reason. Plus, I dont have a trig book handy. thanks, BrianH

Share this post


Link to post
Share on other sites
Advertisement
compute two vectors from your 3 points
then find the length of the cross product. Then divide that number by 2 and that is the area of your triangle. If the number is negative then the cross product got computed in the wrong direction (down maybe) and so just take the absolute value of it.


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail

Share this post


Link to post
Share on other sites
Does that formula work for all triangles? I know it works for right and isosceles triangles. But I am not sure it works for all triangles - scalene for example (all 3 sides different length).

I think there is some extra trig involved in order to compute it for any triangle, I just can't remember what it is.

*** this reply was for TerranFury ***

thanks,

BrianH

Edited by - BrianH on February 19, 2001 11:09:40 AM

Share this post


Link to post
Share on other sites
Assuming my memory and my algebra are correct:

b = sqr((x1-x2)^2+(y1-y2)^2)

And

h = (abs(((y1-y2)/(x1-x2))*x3 - y3 + (y1 - (y1 - y2)/(x1 - x2) * x1))/(sqr(((y1 - y2)/(x1 - x2))^2 + 1))

So the area of a triangle with the following vertexes:

(x1, y1)
(x2, y2)
(x3, y3)

Is determined through the following equation:

A = (0.5)*(sqr((x1-x2)^2+(y1-y2)^2)) * ((abs(((y1-y2)/(x1-x2))*x3 - y3 + (y1 - (y1 - y2)/(x1 - x2) * x1))/(sqr(((y1 - y2)/(x1 - x2))^2 + 1)))

However, you''ll notice that there are many redundant operations within this equation. You can break it down into individual operations, and, for each operation that occurs multiple times, do it once, store it in a variable, and use that. One example that springs to mind is calculation of the slope of a line. There is the expression ((y1 - y2)/(x1 - x2)) multiple times within the equation. You could do that once, store it in a variable called "slope," and then just plug that in where appropriate.

Please note that I''m not sure I''m right. I just did this very quickly, and could very well be wrong. But I think I''m right.

Share this post


Link to post
Share on other sites
just do it my way....it works for any triangle
and is easy
here
    
struct VECTOR
{
float x, y, z;
}
// set up the vectors

VECTOR a, b, cross;
a.x = x2-x1;
a.y = y2-y1;
a.z = z2-z1;
b.x = x3-x1;
b.y = y3-y1;
b.z = z3-z1;
// cross them

cross.x = (a.y*b.z)-(a.z*b.y);
cross.y = -((a.x*b.z)-(a.z*b.x));
cross.z = (a.x*b.y)-(a.y*b.x);
// length of cross

float length = sqrt((cross.x*corss.x)+(cross.y*cross.y)+(cross.z*cross.z));
// one half the length is the area of the triangle

float area = length/2.0;



"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail

Edited by - ncsu121978 on February 19, 2001 11:23:03 AM

Share this post


Link to post
Share on other sites
One thing I forgot to add. sqr is the BASIC square root operator. Use whatever the C++ equivalent is. (sqrt, right?)

But ncsu''s way is probably easier anyway!

Share this post


Link to post
Share on other sites
Hi
From trigonometry, we have the triangle edges as A B and C, and
their corresponding angles as A B and C , and the edges facing
these angles named a b and c. the area S is :

S = a * b * Sin ( C ) / 2

a and b are the length of vectors which can be easily calced, and
C is the angle between two vectors which is :

C = ArcCos ( CB . CA / ( a * b ) )

by . i mean dot product of the two vectors.

--MFC (The Matrix Foundation Crew)

Edited by - Seyedof on February 20, 2001 11:00:15 AM

Share this post


Link to post
Share on other sites
The cross product is easily the best method.
A triangle is made up of vectors a, b, and an implicit third.
Area = (|a||b| sin (angle)) / 2
A property of the cross product is that:
|a x b| = |a||b| sin (angle)

...'nuff said.

Edited by - Beer Hunter on February 20, 2001 12:49:17 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!