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 superflyninja · Mar 29, 2015 at 04:26 PM · 3dvectormaths

Find center point of regular polygon

Hi all, I've written a script to generate an N sided regular polygon shape consisting of cubes.However I want to position the shape so that the camera is at its center point. I was thinking that if I found a point that is the radius of the shape distant from the camera position along an angle of 360- interior angle/2 as the starting point of the shape generation that would work. So for a 4 sided shape, the interior angle is 90 degrees between sides. So half that is 45degrees. So if i started generation at a point the radius distant from the camera position along the direction of -45 degrees that would ensure the camera is central. I know how to find the radius and angle. But I cant seem to get the position right:

 Quaternion theAngle = Quaternion.Euler(0, -angle/2, 0);
 
 Vector3 tdirection = theAngle * Vector3.forward;
 
 initPosition += tdirection * tunnelRadius;

initPosition is the position of the camera. Any ideas? Thanks.

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 Bunny83 · Mar 29, 2015 at 04:45 PM 0
Share

Uhm, i'm a bit confused. Why do you create a regular polygon this way? Usually you would define the center and go around n times with (360/n)°

Also how do you form a polygon out of cubes? You either have a gap between the cubes, or the cubes have to intersect each other.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Mar 29, 2015 at 04:48 PM

Regardless of my questions in the comment above, one way how you can find the center of a regular polygon is by simply take the arithmetic mean of all corners. So simply add up all corner positions and divide by the count.

edit

Something like that:

 Transform[] cubes;
 
 Vector3 FindCenter()
 {
     Vector3 pos = Vector3.zero;
     foreach(Transform t in cubes)
     {
         pos += t.position;
     }
     return pos / cubes.Length;
 }

Comment
Add comment · Show 2 · 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 Bunny83 · Mar 29, 2015 at 05:20 PM 0
Share

Another way is, since you should know the iteration angle and the iteration step size (probably 1.0?!?) You can simply figure out the radius by using:

 float r = s / $$anonymous$$athf.Sin($$anonymous$$athf.PI / n);

To get the direction from one of the corners you can use half of the interior angle (like you have mentioned) and do one of your iteration steps. The next direction would be your desired direction. Don't forget to normalize the direction before you multiply with the radius.

If you want any further help you should include your actual generation code in your question since my answers are purely based on speculations on how you actually generate your polygon. A screenshot would also be nice ^^

avatar image superflyninja · Mar 29, 2015 at 06:43 PM 0
Share

Hmmm. What I need is just the starting point to draw the the shape. I have the shape drawing dandy so no issues there. I have the formula to get the radius no problem, I have the angle and the center point of the shape. Its literally just getting the starting point for the construction is what I need. So for example using the angle and radius on a square shape, it should find the top left corner. I suppose what I need is to be able to set the direction and move the length of the radius out along it.

Im not sure but it seems like the measurements of the camera position etc seem like they might not be fully consistent with the placed cubes. Here is a webplayer of the tunnel that is generated https://t.co/kT7HwTZUDt

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

21 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

Related Questions

Relation between two 3D vectors that are in the same plane, to translate to 2D 4 Answers

determine that the spinning motion is "CW" or "CCW" 0 Answers

Making sprites just rotate and not tilt. 3 Answers

How do I create a vector that always points down locally 1 Answer

How to create Vectrex(Vector) look in games ? 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