c++ - Algorithm to generate a point grid out of a plane equation -


i have plane equation in 3d-space: ax + by + cz + d = 0 , want fill plane within given radius specific point on plane regulary distributed points. seems me, there should mathematical elegant answer, fail see it. answer in c++ or pseudo-code better.

i'll assume have reasonably 3d vector class, , call vec3 in answer. first thing need vector in plane. there few ways generate 1 given normal-plane equation, prefer one:

vec3 getperpendicular(vec3 n) {   // find smallest component   int min=0;   (int i=1; i<3; ++i)     if (abs(n[min])>abs(n[i]))       min=i;    // other 2 indices   int a=(i+1)%3;   int b=(i+2)%3;    vec3 result;   result[i]=0.f;   result[a]=n[b];   result[b]=-n[a];   return result; } 

this construction guarantees dot(n, getperpendicular(n)) zero, orthogonality condition, while keeping magnitude of vector high possible. note setting component smallest magnitude 0 guarantees don't 0,0,0 vector result, unless input. , in case, plane degenerate.

now base vectors in plane:

vec3 n(a,b,c); // a,b,c equation vec3 u=normalize(getperpendicular(n)); vec3 v=cross(u, n); 

now can generate points scaling u , v , adding vector got on plane.

float delta = radius/n; // n how many points want max in 1 direction float epsilon=delta*0.5f;  (float y=-radius; y<radius+epsilon; radius+=delta)    (float x=-radius; x<radius+epsilon; radius+=delta)       if (x*x+y*y < radius*radius) // in circle           addpoint(p+x*u+y*v); // p point on plane 

the epsilon makes sure point count symmetric , don't miss last point on extremes.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -