Note that there are some explanatory texts on larger screens.

plurals
  1. POCartesian to Polar (3d coordinates)
    primarykey
    data
    text
    <p>How do you convert between Cartesian and Polar (and back) coordinate systems in 3D space? Preferably with a c# example but anything would really be appreciated. Thanks!</p> <p><strong>Edit</strong> When 20% of the change is taken into account (not forming a sphere)</p> <p><img src="https://i.stack.imgur.com/DdgoM.png" alt="enter image description here"></p> <p><strong>Edit 2</strong> </p> <pre><code>private void Spherise() { for (int i = 0; i &lt; vertices.Count; i++) { float radius = this.radius; float longitude = 0; float latitude = 0; float sphereRadius = 32; Color color = vertices[i].Color; ToPolar(vertices[i].Position - centre, out radius, out longitude, out latitude); Vector3 position = ToCartesian(sphereRadius, longitude, latitude) + centre; Vector3 normal = vertices[i].Position - centre; normal.Normalize(); const float lerpAmount = 0.6f; Vector3 lerp = (position - vertices[i].Position) * lerpAmount + vertices[i].Position; vertices[i] = new VertexPositionColorNormal(lerp, color, normal); } } private void ToPolar(Vector3 cart, out float radius, out float longitude, out float latitude) { radius = (float)Math.Sqrt((double)(cart.X * cart.X + cart.Y * cart.Y + cart.Z * cart.Z)); longitude = (float)Math.Acos(cart.X / Math.Sqrt(cart.X * cart.X + cart.Y * cart.Y)) * (cart.Y &lt; 0 ? -1 : 1); latitude = (float)Math.Acos(cart.Z / radius) * (cart.Z &lt; 0 ? -1 : 1); } private Vector3 ToCartesian(float radius, float longitude, float latitude) { float x = radius * (float)(Math.Sin(latitude) * Math.Cos(longitude)); float y = radius * (float)(Math.Sin(latitude) * Math.Sin(longitude)); float z = radius * (float)Math.Cos(latitude); return new Vector3(x, y, z); } </code></pre> <p><img src="https://i.stack.imgur.com/1Hsax.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload