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 Matrixmage · Jul 29, 2014 at 10:10 AM · c#mathsphere

How would I make a sphere with equidistant vertices?

I'm trying to make a spherical burst of rays for the purpose of checking collision, but having specific interactions happen based upon what on where each ray hit. Hence why I'm using rays rather then something simpler such as OverlapSphere. But that doesn't really matter so much. The reason I'm looking for how to make a sphere is because I can use the same math for my rays, by having them go to the vertices of where the sphere would be. But every way I can find for making a sphere has the lines get closer the near to the poles, which makes sense, as its pretty easy to do. But as you can imagine, its not that useful for my current project.

TL;DR: How do I make a sphere with equidistant vertices? If its not perfectly equidistant its fine, it just needs to pretty close. If this happens, it would be great if you could give how much the difference would be, and where, if applicable.

Extra notes: I've looked at this and this, but the math is way over my head, so what I've been looking for might've just been staring me in the face this whole time.

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
0

Answer by VesuvianPrime · Jul 29, 2014 at 11:12 AM

Hey Matrixmage

Packing is definitely overkill for this, and I too have trouble reading mathematical proofs.

The following has been my approach in the past:

1) Determine the distance between each vert (in your case, the angle between each ray).

2) Determine the circumference of the sphere = 2 PI radius (in your case, 360.0f)

3) Now we can calculate the number of verts we want to have in one sweep. We only want the verts going down one side of the sphere for now:

alt text

 int halfCircumferenceVertCount = Mathf.Floor((circumference / 2.0f) / distanceBetweenVerts);

4) Don't forget the bottom cap

alt text

 halfCircumferenceVertCount += 1;

5) Now we are going to loop over our vert count and do pretty much the same steps again, but for each horizontal slice:

alt text

 // We don't need to bother with the top or bottom cap here
 for (int index=1; index < halfCircumferenceVertCount - 1; index++)

6) Now this is the hardest part. We need to calculate the circumference of each slice:

alt text

6.1) First we need the angle from the equator:

 float angleFromTop = (index / halfCircumferenceVertCount) * 180.0f;
 float angleFromEquator = 0.0f;
 
 if (angleFromTop <= 90.0f)
     angleFromEquator = 90.0f - angleFromTop;
 else
     angleFromEquator = angleFromTop - 90.0f;

6.2) Now we do some trig to get the circumference of the slice at that angle:

 float sliceCircumference = 2 * PI * radius * Mathf.Cos(Mathf.deg2rad * angleFromEquator);

7) Now we can calculate how many verts are on this slice:

 int sliceCircumferenceVertCount = Mathf.Floor(sliceCircumference / distanceBetweenVerts);

8) We loop through these verts:

 for (int sliceIndex=0; sliceIndex < sliceCircumferenceVertCount; sliceIndex++)
 {
     float angleFromHalfCircumference =
         (sliceIndex / sliceCircumferenceVertCount) * 360.0f;
 
     Quaternion pitch = Quaternion.Euler(-angleFromTop, 0.0f, 0.0f);
     Quaternion yaw = Quaternion.Euler(0.0f, angleFromHalfCircumference, 0.0f);
 
     Quaternion lookAtVert = yaw * pitch;
     Vector3 forward = Vector3.up * lookAtVert;
 
     Physics.Raycast(transform.position, forward, 10.0f);
 }

9) Don't forget to do your raycast for directly up and directly down!

I've written this from memory so there may be some mistakes, but it shouldn't be too hard to figure out where I went wrong. Also I tend to get quaternion multiplication the wrong way around, so that may be wrong.

Thanks, Ves

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Make 3D Player look exactly at mouse with ScreenToWorldPoint? (maths Question) 2 Answers

Drawing a Mandelbrot Set problem 0 Answers

How to move an object over a distance in a direction? 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