I need to find the center of a triangle in 3D space, help!

I need to find the center of a triangle in 3D space, help!

I am creating my own graphics library that does alpha-blending,
anti-aliasing, tri-linear buffering, and all that stuff (software based)....

My only problem is I need to know how to rotate around the objects center,
so i need to know how to rotate around the center of a triangle!! Right now,
it is rotating around the origin and looks horrible.

Does anyone know how to find the center point of a triangle from the
coordinates of 3 vertices?? And does anybody know the formula (without
matrices! !yikes!) to rotate an object around a specific point? Like if i
wanted to rotate a triangle around point (2,2,1)??  [x,y,z]

I need to find the center of a triangle in 3D space, help!

On Fri, 30 Jan 1998 21:52:46 -0500 in comp.os.msdos.djgpp Ted Gress

: My only problem is I need to know how to rotate around the objects center,
: so i need to know how to rotate around the center of a triangle!! Right now,
: it is rotating around the origin and looks horrible.

Define `center' :).  There are several points you could mean.  I think
it's most likely that you mean the centre of gravity.  Finding this
is simple -- you just take the arithmetic mean of the values of each
coordinate, i.e. if your triangle is at (a0,a1,a2), (b0,b1,b2),
(c0,c1,c2) then the centre of mass is at ((a0+b0+c0)/3, (a1+b1+c1)/3,
(a2+b2+c2)/3).

: Does anyone know how to find the center point of a triangle from the
: coordinates of 3 vertices?? And does anybody know the formula (without
: matrices! !yikes!) to rotate an object around a specific point? Like if i
: wanted to rotate a triangle around point (2,2,1)??  [x,y,z]

Remember that in 3D you rotate around an axis, not a point.  While
it's possible to do it without matrices, I can't go into that here --
IMHO it will be far simpler if you just use matrices. :)  They're not
really hard to use at all, if you know the rules.

--

I need to find the center of a triangle in 3D space, help!

Try comp.graphics.algorithms...

--
.*.  Friendship, companionship, love, and having fun are the reasons for
-()  <  life. All else; sex, money, fame, etc.; are just to get/express these.
`*'  Send any and all mail with attachments to the hotmail address please.

I need to find the center of a triangle in 3D space, help!

Quote:Ted Gress writes:
>Does anyone know how to find the center point of a triangle from the
>coordinates of 3 vertices??

The "center" of a 3d object is not a very well defined concept, but for
most purposes just averaging the three vertices would do the trick.

Quote:>And does anybody know the formula (without matrices! !yikes!) to rotate

an object around a specific point?

Translate it to the origin, rotate it around the origin, and then
translate back to the original position.

But why do you say "without matrices"? IMHO matrices are the only
sensible way to do something like this, because they provide an easy way
to concatenate the translations and rotation into a single transform
rather than having to do each operation as a separate step. They aren't
nearly as complicated as they seem when you first look at them, and can
make your code far more robust, flexible, and efficient.

btw. this sort of question is not appropriate for a djgpp newsgroup:
comp.graphics.algorithms would be a much better place to ask.

--

"Pigs use it for a tambourine" - Frank Zappa

I need to find the center of a triangle in 3D space, help!

I'll see if my news server handles that. Thanks again!

=-)

>Try comp.graphics.algorithms...

>--
>    .*.  Friendship, companionship, love, and having fun are the reasons
for
> -()  <  life. All else; sex, money, fame, etc.; are just to get/express
these.
>    `*'  Send any and all mail with attachments to the hotmail address

if (x0, y0, z0) and (x1, y1, z1), any way to tell which triangle is
infront and which in behind?

I can do that with very complicated mathematical calculation, but I
prefer a better way for faster computing.