- Home /
Mid point of a triangle
is there any built in easy way to find the mid point of a triangle in a mesh.
Basically i want to find the nearest face and then cast towards it. I can do nearest vertex on a mesh fairly easy but i want to cast towards the nearest "face" not the nearest mesh (this has importance due to wanting to take the nearest face of one object and rotate it to be parallel to another, as such nearest vertex really won't work for me)
i'm not sure if there is a function that would do it easy (it seems like for lighting or something it'd actually be useful information so i was hoping it mgiht be built in somehwere)
if not the math behind it perhaps if you know it?
i'm thinking Maybe if you have points A B C
the mid point is something like the intersection of line
A -> midpoint of(B,C) B -> midpoint of (A,C) C -> midpoint of (A,B)
though i think that last step might be redundant i think C crosses at the same point as A to mid and B to mid cross.
is this right?
Spark -- mathematically the midpoint of a triangle is incredibly simple. You just add all three vertices and divide by three.
(Note that there are "different sorts" of midpoints in triangles - read any wikipedia article on it - but that's all you need for your situation.)
Just as you say - you use this constantly, every other line of code, when dealing with mesh, lighting, collisions, whatever.
sometimes you might keep a handy array, with that midpoint of each triangle in your mesh (just computer it before hand you know).
Answer by DaveA · Mar 26, 2013 at 07:59 AM
This may be useful: http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-barycentricCoordinate.html
Barycentric (mid) point is (A + B + C) / 3
Dave .. I'm pretty sure this IS WRONG dude
the barycentric center is not (A+B+C)/3
it's quite hard to compute the barycentre. (which just means the center of mass.) Unity does the calculation for you just as you say with that function.
the "actual" "everyday" "normal" center of a triangle is (A+B+C)/3. this is unrelated to the "barycentric center".
Answer by Maulik2208 · Mar 26, 2013 at 08:00 AM
ya in mathematical terms this way will work Good for Even Sized(having all surface of same length) triangles....... but in the case of others please Follow this link ---> Center of Triangle one more thing i have only suggested mathematical way......
Don't forget to mark the answer if found useful
the arithmetic (A+B+C)/3 will always and every time give you the correct midpoint of a triangle.
regarding the "center of mass", Unity's function will always and every time give you the correct result.
(Recall too that in a functioning mesh, you can not have bad/unreal/wrong-winding etc triangles.)
As you say, regarding the "other" mathematical definitions of various centre properties of a triangle, some do not apply to certain triangles, just as you say.
Your answer
Follow this Question
Related Questions
Math question, angles and magnitude stuff 2 Answers
Calculate mid angle position based on three points 1 Answer
How to transform/rotate a vector onto the same plane as another vector 2 Answers
nearest point on mesh? 3 Answers
How to properly offset a Handles.DrawSolidArc by an angle in different axis? 2 Answers