Jump to content

Creating the Vertice of a Sphere Polar coordinate in VEX


ezza

Recommended Posts

hello, I'm trying to mesh a group of point, from an array.

It gives a meshed sphere but with hole, and overlapping points.

I guess I shd use some condition but I'm not really sure how..

int total =40;
int prim;
float r = 200.0;

float   lon    = -($PI); //-pi,pi
float   lat     = -($PI)/2;//-pi/2, pi/2

float   step_lon = lon/total; //angle sur la longitude
float   step_lat  = lat/total;//angle sur la latitude

int globe[] = {0,0,0};
 

for (int i=0 ; i<total+1; i++){
for (int j=0; j< total+2; j++){

   //polar to cartesian
   float x = r * sin(lon) * cos(lat);
   float y = r * sin(lon) * sin(lat);
   float z = r * cos(lon);

  //vector pos
  vector pos = set(x,y,z);
     
     //feed array, create points sphere
     globe[j]=addpoint(geoself(), pos);
               
     int v1 = globe[j];
     int v2 = globe[j+1];
     int v3 = globe[j+2];
           
     prim = addprim(geoself(), "poly");
     
     addvertex(geoself(), prim, v1);
     addvertex(geoself(), prim, v2);
     addvertex(geoself(), prim, v3);
     
     //setpointattrib(geoself(), "lat", v1, j, "set");
    // setpointattrib(geoself(), "lat", v2, j+1, "set");
     //setpointattrib(geoself(), "lat", v3, j+2, "set");
       
    lat += step_lat;
    }                               

lon +=step_lon;


}

 

IT Looks like it miss half of the primitives.

sphere.jpg

thks

HIP FILE :

sphere_od.hipnc

Edited by ezza
Link to comment
Share on other sites

Are you trying to generate UV sphere? If I understand your goal correctly, using last 4 points is wrong technique here. It will only produce blade-like polygons. You need to determine primitives's point numbers by looking at generated points's numbers and possibly visualizing i and j values.

uv_sphere.PNG

 

// Detail wrangle.

#include "voplib.h"

int rows = chi("rows");
int cols = chi("cols");
float radius = ch("radius");

for (int i = 0; i < rows; i++)
{
    float step_lon = PI / (rows - 1);
    float lon = i * step_lon;

    for (int j = 0; j < cols; j++)
    {
        float step_lat = 2 * PI / cols;
        float lat = j * step_lat;

        addpoint(0, vop_frompolar(lat, lon, radius));

        if (i+1 == rows)
            continue;

        int prim = addprim(0, "poly");
        int v1 = i*cols + j;
        int v2 = i*cols + (j+1)%cols;
        int v3 = v2 + cols;
        int v4 = v1 + cols;
        addvertex(0, prim, v1);
        addvertex(0, prim, v2);
        addvertex(0, prim, v3);
        addvertex(0, prim, v4);
    }
}

 

uv_sphere.hipnc

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...