Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
0
Question by IrishSenthil · Mar 02, 2020 at 02:57 AM · meshanglestriangles

How to calculate internal angles of a mesh triangle?

Hi Guys!

I'm trying to find the internal angles a, b and c of the triangle in the picture below. The red points form a triangle of a mesh. I know the Vector3 positions of the red points and the normal of the triangle, but I don't know how to work out the angles between these points. How do I do this?

My triangle is below: alt text

vla396goa6k41.png (8.8 kB)
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Mar 02, 2020 at 05:09 AM

Well, you can simply use Unity's Vector3.Angle method like this:

 public static float GetVectorInternalAngle(Vector3 a, Vector3 b, Vector3 c)
 {
     return Vector3.Angle(b-a, c-a);
 }


Following is an explanation what's actually happening here. You can ignore the following unless you are interested what happens behind the scenes.


What we actually do here is calculate the two vectors that meet at point a. The Angle function simply calculates the dot product between the two vectors which is just multiplying the two vectors component wise and adding all values up to a single value. This value has the nice property that it's the product of the lengths of the two vectors multiplied by the cosine of the angle between them.


To actually get the angle we just have to divide that value by the lengths of both vectors. To calculate the length of a vector we just use the Pythagorean Theorem. Unity's Vector3 struct does this calculation for us with the "magnitude" property. Though since we have to divide through both vector lengths the Angle function calculates the product using only one square root for both lengths.


Once the value is divided by the lengths the remaining value represents the cosine of the angle we're looking for. Now we could simply use the arcus cosine function (Acos()). However due to floating point imprecisions the Angle function first clamps the value between -1 and 1 because the arcus cosine of a value smaller than -1 or greater than 1 is not defined and would result in a NaN (Not a Number) value.


In actual mathematics and computer science the trigonometric functions (sine, cosine, tangent, ...) do not work in degrees but in radians. A full "360°" turn equals 2*PI in radians. So a value of PI represents 180°. To convert the angle in radians to degree we just have to divide by PI and multiply by 180. Unity's Mathf class provides this as a precalculated factor "Mathf.Rad2Deg".

Comment
Add comment · Show 3 · 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 Sanjay97123 · Dec 30, 2021 at 05:38 AM 0
Share

any idea how to get internal angles of a square ?alt text

square.png (2.6 kB)
avatar image Bunny83 Sanjay97123 · Dec 30, 2021 at 09:19 AM 0
Share

Well, all internal angles of a square (or rectangle) are 90°, otherwise it's not a square (rectangle) :) Maybe you think about a quadrilateral (or quad for short)? Well if the mesh / submesh actually has "Quads" as topology it would work similarly. You just need to use 3 consecutive points with the method I've posted above. Note that the "middle" point (or the point you want to get the angle from) is the point "a" in my method. The other two points are simply the neighboring points.


However if the mesh is an actual triangle mesh, there's no general meaningful way to "combine" triangles into quads. So unless you specify the 4 points exactly, there's not much you can do here.


If you have a more concrete example, please ask a seperate question. Feel free to include a link to this question but don't forget to explain your specific problem more in detail.

avatar image Sanjay97123 Bunny83 · Jan 01 at 08:38 AM 0
Share

Thanks for answering, after modifying the above method getInternalvector i figured it how toalt text do it

screenshot-19.png (284.2 kB)
avatar image
0

Answer by IrishSenthil · Mar 02, 2020 at 04:03 AM

Hi Guys,

I figured it out. Here is my solution:

 public static float GetVectorInternalAngle(Vector3 a, Vector3 b, Vector3 c)
 {
     double num = (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y) + (b.z - a.z) * (c.z - a.z);

     double den = Math.Sqrt(Math.Pow((b.x - a.x), 2) + Math.Pow((b.y - a.y), 2) + Math.Pow((b.z - a.z), 2)) *
                  Math.Sqrt(Math.Pow((c.x - a.x), 2) + Math.Pow((c.y - a.y), 2) + Math.Pow((c.z - a.z), 2));

     double angle = Math.Acos(num / den) * (180.0 / Math.PI);

     return (float) angle;
 }
Comment
Add comment · 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
0

Answer by Sanjay97123 · Jan 01 at 08:48 AM

This Works For Square

public static float GetVectorInternalAngle(Vector3 a, Vector3 b, Vector3 c,Vector3 d) { Vector3 from = d-a; Vector3 to = a-b; return Vector3.Angle(-from, to); }

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

136 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Understanding verts and triangles in Unity 1 Answer

Triangles on my mesh don't show 1 Answer

How does the Triangles work on Mesh? 1 Answer

Strange issue with generated mesh 2 Answers

Optimized vertex manipulation 1 Answer


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