• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by sparkzbarca · Mar 26, 2013 at 07:47 AM · mathtrigonometry

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?

Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 26, 2013 at 08:14 AM 0
Share

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).

2 Replies

  • Sort: 
avatar image
Best Answer

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

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 26, 2013 at 08:21 AM 0
Share

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".

avatar image

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

Comment
sparkzbarca

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 26, 2013 at 08:24 AM 0
Share

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.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

clamp rotation by mouse direction 0 Answers

Custom LookAt and what's the math behind it 0 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges