Meshes - Moving a point away from a centre - A geometry question?

Hello, (and Hello! as this is my first post)

I have a question about moving a point away from a center on the same trajectory, in effect what happens if you scale something up in 3d, but on a point-by-point basis.

I’m playing around with generating meshes. At the moment making points around a circle with what I believe is
converting polar coordinates to cartesian co-ordinates. (angle = degtorad, cos(angle) * radius, sin(angle) * radius)

My question is if I want to move one of those points away from from the centre (ideally in a vec3f 3d space, but it should be the same for either I would think)

I know how to move them all (at least at the initial generation stage) by changing the radius value in the psuedocode above.

But say I only want to move a single point, how would I go about that?
I can vaguely envision a way by converting cartesian to polar then back again, but that seems quite long winded, especially if it needs to be run within a loop for every point.

I’m hoping there’s some geometrical magic that can be done here?

Anyone got any clues?

To give a bit of background, what I’m hoping to do is make a spherical / cylindrical mesh where the vertices move towards and away from the centre (perhaps via a sin wave) making a sort’ve wobbly, amorphous blob.

Well, the equation of a sphere is something like:

  
  
for (double phi = 0.; phi < 2*PI; phi += PI/10.) // Azimuth [0, 2PI]  
    {  
        for (double theta = 0.; theta < PI; theta += PI/10.) // Elevation [0, PI]  
        {  
            ofVec3f point;  
            point.x = r * cos(phi) * sin(theta) + center.x;  
            point.y = r * sin(phi) * sin(theta) + center.y;  
            point.z = r            * cos(theta) + center.z;  
            spherePoints.push_back(point);          
        }  
    }  
  

So you can just manipulate on one axis, if that helps? I’m not quite following what you’re trying to do, so this might not be that helpful :slight_smile:

1 Like

If you would like to move individual points from in a mesh from a point in space and only create the mesh once. You can create your sphere mesh and then manipulate the points after it is created. Make them react to audio or anything else.
You could get the vector to the center. And multiply by the desired distance. It should apply to all types of meshes. For example. (pseudo code)

  
  
// first grab a vertex //  
ofVec3f myPoint = myMesh.getVertex( 0 );  
// the point you want to offset your vertex from //  
ofVec3f center(ofGetWidth(), ofGetHeight(), 0);  
ofVec3f normal = center - myPoint;  
// move 20.0f units away from center //  
float offsetDistance = 20.0f;   
normal.normalize();  
myPoint += (normal * offsetDistance);  
// then you have to set it back in the mesh //  
myMesh.setVertex( 0, myPoint );  
  

2 Likes