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 thenachotech1113 · Feb 14, 2015 at 05:23 PM · proceduralspherecircle

creating a procedural sphere

hello, I am trying to create a procedural sphere for a space game, i want a planet that the further you go the less vertices it has. This is most likely not the best way to do it but it was the only way i could think of. It consists of creating a series of circles, both "poles" would be a single vertex, then apropiately conecting the vertices in triangles. the creation of the circles is where I am currently stuck at. to create them i used the following:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Create_Sphere : MonoBehaviour {
 
     public int lons;
     public int lats;
     public float radius;
 
     public List <Vector3> points = new List<Vector3>();
 
     void Start () 
     {
         CreateCircle();
     }
     void CreateCircle ()
     {
         points.Add(new Vector3(0, 0, 0));
 
         for (int i = 0; i < lons * 2; i++)
         {
 //calculate the angle between points
             float ang = 180/  lons;
 //calculate the points x and z position
             float x = radius * Mathf.Cos(i * ang);
             float z = radius * Mathf.Sin(i * ang);
 //add the points to a List
             points.Add(new Vector3(x, 0, z));
         }
 //visualy display the points
         DisplayPoints();
     }
     void DisplayPoints ()
     {
         for (int i = 0; i < points.Count; i++)
         {
             GameObject dspl = GameObject.CreatePrimitive(PrimitiveType.Cube);
             dspl.transform.position = points [i];
         }
     }
 }


the problem is, though it does create them at an apropiate distance from the center but as if it had the wrong angle, for example, when creating 2, the ang variable says 180 but it seams to create it at 120 or so. but when there are 3, ang var says 120, but they are on something like a 20 deg. no idea what is going on so thanks a lot to everyone for reading this question and sorry for making it so long.

p.s. all i am trying to create for now is the circle

Comment
Add comment · Show 2
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 Glurth · Feb 14, 2015 at 05:55 PM 0
Share

points.Add(new Vector3(x, 0, z));

This does not seem right for points on a sphere. ALL Cartesian (x,y,z) coordinates should change for each lat/long.

http://en.wikipedia.org/wiki/Spherical_coordinate_system check out the section on "Cartesian coordinates", it will have the formula you are looking for, that converts from spherical(Radius, lat,long) to cartesian(x,y,z) coordiantes.

(using this formula, you will want to create two loops(nested). One for lat, one for long.)

avatar image thenachotech1113 · Feb 14, 2015 at 09:25 PM 0
Share

oh, yea ik, thanks for pointing that out. For now im trying to create just a cicle, before i move one to create the whole sphere, to keep it simple. Sory for not specifying.

0 Replies

· Add your reply
  • Sort: 

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 to keep an object within a circle/sphere (radius) - NO RECTANGLE 3 Answers

How to find the radius area of linerencderer drawn circle and move objects inside ? 1 Answer

irregularities with procedurally generated sphere 1 Answer

Clamp x,y within circle, z to sphere 0 Answers

How to create a terrain in a sphere with Perlin Noise 0 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