Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Diegar · Jun 21, 2020 at 08:58 PM · angleverticescircle

Get Vertices of Circle Facing Any Direction

Been trying to figure this out on my own, but stuck, and not finding any resources which help me with this (or i lack the correct terminology to ask the right question). Trying to get the vertices of a circle facing any direction (x, y, z). Found lots of help on doing this in 2D space, or 3D if one vector is static, but needing help with facing in any direction in 3D space.

     private void createCircle(Vector3 center, Vector3 next, float radius, int vertCount, int count)
     {
         // get direction of plane
         Vector3 heading = next - center;
 
         // get vertices of circle facing heading (x, y, z), and add them to vertices[]
         int arrayCount = (count - 1) * vertCount;
         for (int d = 0; d < vertCount; d++)
         {
             // get each vertex of cicle
             Vector3 vertex;
             
             // add vertex to array
             vertices[arrayCount] = vertex;
         }
     }

The center of the circle will be at 'center' and 'next' will be the where the circle will face. Then I'll add each vertex to my array. Need help with the equation to define 'vertex'

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Namey5 · Jun 22, 2020 at 12:05 AM

I'm sure you could do it with some 3D trigonometry, but to make things a bit simpler you can also get the same result by finding one vertex and rotating it around the centre. Something like this should work;

 private void createCircle(Vector3 center, Vector3 next, float radius, int vertCount, int count)
 {
     // get direction of plane
     Vector3 normal = (next - center).normalized;
 
     //Cross product will always return a vector perpendicular to its inputs, so anything will do for the second input so long as it isn't equal to normal
     Vector3 tangent = Vector3.Cross (normal, (normal == Vector3.up) ? Vector3.forward : Vector3.up).normalized;
  
     // get vertices of circle facing heading (x, y, z), and add them to vertices[]
     int arrayCount = (count - 1) * vertCount;
     for (int d = 0; d < vertCount; d++)
     {
         //Rotate the tangent around the circle and scale by radius
         Vector3 vertex = centre + (Quaternion.AngleAxis ((d / (float)vertCount) * 360f, normal) * tangent) * radius;
              
         // add vertex to array
         vertices[arrayCount] = vertex;
     }
 }
Comment
Add comment · 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 Diegar · Jun 23, 2020 at 02:01 AM 0
Share

Was looking for the 3D Trig option, but this helps, and works well. Thank you!

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

129 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

Related Questions

Rotation circle to stop at a certain angle 1 Answer

How to create vector within triangle plane, from perpendiculor vector3 1 Answer

Draw only part of a circle 0 Answers

Make Camera Angle Equal Circle Tangent 2 Answers

How do I make a rotatable procedural circle in 3d space? 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