Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 BrokawBound · Oct 18, 2018 at 06:18 PM · mathcircles

Math question - Circle from n straight lines or planes, end to end

I can't seem to find this math equation on Google, the examples do not go from end to end, instead the lines cross over each other.

I am looking for the equation for n straight lines (2D), or planes (3D), that gives me the [n].transform.position and [n].transform.Eulerangels so that they make a circle end to end (meaning where one line ends, the next begins).

Comment
Add comment · 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 Eno-Khaon · Oct 18, 2018 at 06:59 PM 0
Share

I'm not entirely clear what you mean regarding the lines crossing over each other.

If you had 6 points around a circle, with each point at...

 // Example using degrees
 sin(0)
 sin(60)
 sin(120)
 sin(180)
 sin(240)
 sin(300)

... then, wouldn't the center of each be the center between each pair of points in order, the width as the distance between those two points, and (Euler angle) rotation as the mid-point between their angle inputs?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TreyH · Oct 18, 2018 at 08:27 PM

Sure, so it's pretty straightforward if you're comfortable with geometry.

Drop this into an empty scene and play around with the inspector fields to see it work with different configurations. You should see something resembling:

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CircleFromLines : MonoBehaviour {
 
     public int sides = 6;
     public int radius = 7;
     public int z = 5;
 
     // We'll use cubes for this
     private List<GameObject> blocks;
 
     // Update is called once per frame
     void Recalculate()
     {
         // Create if necessary
         if (this.blocks == null)
             this.blocks = new List<GameObject>();
         
         // Clear if necessary
         for (int k=0; k<this.blocks.Count; k++)
             GameObject.Destroy(this.blocks[k]);
         
         // How far apart our pieces are from the center
         float innerAngle = 360f / this.sides;
 
         // Create them
         for (int k=0; k<this.sides; k++)
         {
             // Create the block
             var block = GameObject.CreatePrimitive(PrimitiveType.Cube);
 
             // Get position and the angle values
             int index = k % this.sides;
             float degrees = index * innerAngle;
             float radians = Mathf.Deg2Rad * degrees;
             float x = this.radius * Mathf.Cos(radians);
             float y = this.radius * Mathf.Sin(radians);
 
             // Determine their length
             float length = 2 * this.radius * Mathf.Abs(Mathf.Tan(Mathf.Deg2Rad * innerAngle / 2));
 
             // Then scale, rotate, and move them.  We'll keep all but one dimension small
             block.transform.localScale = new Vector3(0.2f, length, 0.2f);
             block.transform.rotation = Quaternion.Euler(0, 0, degrees);
             block.transform.position = new Vector3(x, y, this.z);
 
             this.blocks.Add(block);
         }
     }
 
     void OnGUI()
     {
         if (GUI.Button(new Rect(0, 0, 100, 50), "Recalculate"))
         {
             this.Recalculate();
         }
     }
 }
 



circle-segments-2.png (69.9 kB)
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 BrokawBound · Oct 19, 2018 at 12:17 AM 0
Share

This works great! The only issue I am having, with the blocks being 3d objects, they are connected top to bottom (on the Y plane). If I switch from a cube to a plane or a straight line, the ends are always on the X plane. When I change the localScale to (length, 1, 1) they still try to attach from top to bottom.

I think I can figure it out though, playing around with it still. Thank you so much for this code!

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

100 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

Related Questions

Collidiers intersection 1 Answer

How to draw a circle around a moving game object 1 Answer

How to build a car script that allows for car to turn in full circles 1 Answer

How to get 0-360 degree from two points 2 Answers

Calorie tracker 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