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 Kytuzian · Jan 02, 2014 at 02:46 AM · sphereplanevectorplanet

How to place objects from a 2d plane around a sphere?

I have a 2d plane which is the surface a planet. The planet is composed of square of varying heights, and I want to place them around a sphere so that these squares more or less make up the outside of the sphere.

This the created shape: http://gyazo.com/d2b7f5dd956ba373b3a2bc03578678cf.png

Here is my code for placing the objects, in which x and y are the coordinates on the 2d plane. I believe it makes sense, but it could also make none at all.

 float ActualX = x * TerrainBase.transform.localScale.x;
 float ActualY = y * TerrainBase.transform.localScale.z;
                             
 float d = Vector2.Distance(new Vector2(ActualX, ActualY), new Vector2()) / Draw.Radius;
                             
 Position.x = Mathf.Cos(d) * Draw.Radius + Draw.Position.x;
 Position.z = Mathf.Sin(d) * Draw.Radius + Draw.Position.z;
 Position.y = Mathf.Sqrt(Mathf.Pow(Draw.Radius, 2) - Mathf.Pow (Position.x, 2) - Mathf.Pow (Position.z, 2)) + Draw.Position.y;
                             
 Quaternion Rotation = Quaternion.LookRotation(Utility.GetNormalVector(Position, Draw.Position));
 Draw.Map[x][y].Self = (GameObject)GameObject.Instantiate(TerrainBase, Position, Rotation);

y and z have been flipped due to y being up and down in Unity.

ActualX and ActualY are the x and y scaled by the size of the TerrainBase (which is the object I'm using as a base).

d is the angle in radians from the center of the sphere because: 2 pi r = circumference A circle has 2 pi degrees, so to find the angle you would calculate the distance (Vector2.Distance()), divide it by the circumference to find the percentage, then use that percentage time the full measure of a circle which is 2 pi, or simple divide the distance by the radius.

The x position is the cosine of that angle times the length (the Radius) and offset by the x position of the planet. The y position is the sine of that angle times the same length and offset by the z position. The z position can be found because simple algebra, because x^2 + y^2 + z^2 = r^2 for a sphere. Therefore z = sqrt(r^2 - x^2 - y^2).

Finally the rotation is found by using the normal vector of the difference between the position of the new piece of terrain and the center of the planet using Quartenion.LookRotation() and then the object is added to the world.

In the likely event this process doesn't make any sense, please help me anyway. I tried.

Thanks for any help!

Comment
Add comment · Show 5
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 robertbu · Jan 02, 2014 at 02:48 AM 0
Share

I don't see a question here. Are you looking for a solution to place your planes evenly around a sphere?

avatar image HappyMoo · Jan 02, 2014 at 02:54 AM 0
Share

Not sure I undertand what you want. Do you want to place columns on a sphere so you basically get a Terrain on a sphere by having columns of different height? But you don't scale the column yet to get different heights, right? Also, have you considered generating the $$anonymous$$esh ins$$anonymous$$d of instantiating columns?

avatar image robertbu · Jan 02, 2014 at 02:55 AM 0
Share

Take a look at this question:

http://answers.unity3d.com/questions/410992/how-do-i-get-raycasts-to-cast-symmetrically.html

Part way down the page you will see the function UniformPointsOnSphere(). This will allow you find all the positions.

avatar image sparkzbarca · Jan 02, 2014 at 03:52 AM 0
Share

please mark as answered :)

avatar image Kytuzian · Jan 02, 2014 at 04:01 AM 0
Share

I can't mark anyone else as the answerer since no one else actually posted an answer, so I marked myself. Sorry robertbu

1 Reply

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

Answer by Kytuzian · Jan 02, 2014 at 03:43 AM

Yes thank you, I was looking for a solution for just that. I suppose the question was quite clear, as I meant that I had a bunch of rectangular prisms all set with 2d coordinates that I wanted to transform into 3d coordinates around a sphere.

I used the link from robertu.

Thanks!

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

20 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

Related Questions

How do you make a sphere from 6 planes? 1 Answer

How do you create a sphere form 6 planes? 0 Answers

Align an axis to a plane 0 Answers

areas(continents) on my spherical planet 1 Answer

how to make gravity in the center of a sphere 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