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
1
Question by Caiuse · Dec 02, 2012 at 10:25 PM · cubespheremapping

Mapping a cube to a sphere

I found this great articles http://mathproofs.blogspot.co.uk/2005/07/mapping-cube-to-sphere.html which describes mathematically how to map a cube to sphere, I was wondering how I could translate this into unity to map a programmatically generated cube mesh into a sphere?

I translated the equation into C# but I have no idea what I'm doing with it?

 sx = x * Mathf.Sqrt(1.0f - y * y * 0.5f - z * z * 0.5f + y * y * z * z / 3.0f);
 sy = y * Mathf.Sqrt(1.0f - z * z * 0.5f - x * x * 0.5f + z * z * x * x / 3.0f);
 sz = z * Mathf.Sqrt(1.0f - x * x * 0.5f - y * y * 0.5f + x * x * y * y / 3.0f);


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
2
Best Answer

Answer by Bunny83 · Dec 02, 2012 at 10:47 PM

It seems you try the same thing that we do in this question.

While it seems that your forumla is correct, it's just a complicated way of normalizing the vector ;)

Just take a position on the cube and normalize it.

 var CubePoint = new Vector(cubeX, cubeY, cubeZ);
 var SpherePoint = CubePoint.normalized;

This will map a point on the cube surface to the corresponding point on the unit sphere. Just multiply the vector with an float value to change the radius

 var SpherePoint = CubePoint.normalized * radius;


Comment
Add comment · Show 9 · 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 Caiuse · Dec 02, 2012 at 11:41 PM 0
Share

Thanks for the reply, I tried what your suggested and it just seems to make a larger cube. I'm using the primitive cube and normalizing each vert.

avatar image Bunny83 · Dec 02, 2012 at 11:54 PM 1
Share

uhm... the primitive cube has only 4 verts per face. You need much more to do this transformation. Just look at the example in the post you've linked:

Your cube only has the corner vertices which are of course connected with straight lines. When you map the corners onto the unit sphere, it will still look like a cube. You just need more vertices. In my test project (hopefully i will post it the next days) i currently use a 64x64 grid on each cube face while you use a 1x1 grid ;)

avatar image Caiuse · Dec 03, 2012 at 12:05 AM 0
Share

Perfect!! I've been wanting to achieve this for ages, Thanks @Bunny83 I'm working on the height map side of things now, using that original question helps a bunch.

avatar image Bunny83 · Dec 03, 2012 at 12:12 AM 0
Share

btw. there's another problem with your formula and the unity primitive cube: The formula only works with cube coordinates between -1 and 1. Unity's cube vertices are between -0.5 and 0.5. This breaks the cube deffinition which this formula is based on.

I'm still impressed by the formula ;) It's a lot more complicated and only works with cube-surface coordinates as input. Normalizing is much simpler and works with any input.

btw just in case you don't know what normalizing does, here's the formula:

 length = $$anonymous$$athf.Sqrt(x*x + y*y + z*z);
 sx = x / length
 sy = y / length
 sz = z / length
avatar image Bunny83 · Dec 03, 2012 at 12:15 AM 0
Share

No problem ;)

The spherifying and the heightmapping is quite easy. The real problem is to fix the edges between the 6 meshes.

Show more comments

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

10 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

Related Questions

Simplex Noise/ Perlin Noise a Cube Sphere 1 Answer

Adjusting strange Vector3.Normalize behaviour 2 Answers

pop up between 2 colliders: bug or not? 1 Answer

Cube starts shaking when placed on a giant sphere 1 Answer

Maping cube to sphere. Help. 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