generar procedimentalmente una malla de esfera


Estoy buscando un algoritmo (en pseudo código) que genere las coordenadas 3d de una malla de esfera como esta:

texto alt

El número de cortes horizontales y laterales debe ser configurable

 25
Author: afuzzyllama, 2010-11-02

4 answers

Si hay M líneas de latitud (horizontal) y N líneas de longitud (vertical), a continuación, poner puntos en

(x, y, z) = (sin(Pi * m/M) cos(2Pi * n/N), sin(Pi * m/M) pecado(2Pi * n/N), cos(Pi * m/M))

Para cada m en { 0, ..., M } y n en { 0, ..., N-1 } y dibujar los segmentos de línea entre los puntos, en consecuencia.

Editar: puede ajustar M por 1 o 2 según sea necesario, porque debe decidir si contar o no las "líneas de latitud" en los polos

 34
Author: Jonathan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-02 20:55:21

Esto se me acaba de ocurrir sin probarlo. Podría ser un buen punto de partida. Esto le dará los resultados más precisos y personalizables con el mayor grado de precisión si utiliza double.

public void generateSphere(3DPoint center, 3DPoint northPoint, int longNum, int latNum){
     //Find radius using simple length equation (distance between center and northPoint)

     //Find southPoint using radius.

     //Cut the line segment from northPoint to southPoint into the latitudinal number
     //These will be the number of horizontal slices (ie. equator)

     //Then divide 360 degrees by the longitudinal number to find the number of vertical slices.

     //Use trigonometry to determine the angle and then the curcumference point for each circle starting from the top.

    //Stores these points in however format you want and return the data structure. 

}
 2
Author: bhavinp,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-02 20:58:46

Solo una suposición, probablemente podría usar la fórmula para una esfera centrada en (0,0,0)

x²+y²+z²=1

Resuelve esto para x, luego haz un bucle a través de un conjunto de valores para y y z y traza con tu x calculado.

 1
Author: John Boker,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-02 20:47:00

Este es un código C # de trabajo para la respuesta anterior:

using UnityEngine;

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class ProcSphere : MonoBehaviour
{

    private Mesh mesh;
    private Vector3[] vertices;

    public int horizontalLines, verticalLines;
    public int radius;

    private void Awake()
    {
        GetComponent<MeshFilter>().mesh = mesh = new Mesh();
        mesh.name = "sphere";
        vertices = new Vector3[horizontalLines * verticalLines];
        int index = 0;
        for (int m = 0; m < horizontalLines; m++)
        {
            for (int n = 0; n < verticalLines - 1; n++)
            {
                float x = Mathf.Sin(Mathf.PI * m/horizontalLines) * Mathf.Cos(2 * Mathf.PI * n/verticalLines);
                float y = Mathf.Sin(Mathf.PI * m/horizontalLines) * Mathf.Sin(2 * Mathf.PI * n/verticalLines);
                float z = Mathf.Cos(Mathf.PI * m / horizontalLines);
                vertices[index++] = new Vector3(x, y, z) * radius;
            }
        }
        mesh.vertices = vertices;
    }

    private void OnDrawGizmos()
    {
        if (vertices == null) {
            return;
        }
        for (int i = 0; i < vertices.Length; i++) {
            Gizmos.color = Color.black;
            Gizmos.DrawSphere(transform.TransformPoint(vertices[i]), 0.1f);
        }
    }
}
 0
Author: yshahak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-22 08:05:19