c++ - How to Twirl, Whirl, Spiral in dimensions higher than 2D -


i have code following in c++:

for(int x = position.x; x < position.x + dimensions.x; ++x) {     for(int y = position.y; y < position.y + dimensions.y; ++y)     {         glm::vec2 tc = glm::vec2(x,y);         tc -= spiralposition;         float distance = glm::length(tc-position);         if(distance < spiralradius)         {             float percent = (spiralradius - distance) / spiralradius;             float theta = percent * percent * angle;             float s = std::sin(theta);             float c = std::cos(theta);             tc = glm::vec2(glm::dot(tc,glm::vec2(c,-s)),glm::dot(tc,glm::vec2(s,c)));         }         tc += spiralposition;         returnvalues[x][y] = noise->getvalue(tc);     } } 

what does, produces container of gradient noise values. while this, spirals results around epicentre, cyclone. it's based on code here, results identical:

http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl/

what i'd extend 3d, 4d, nd.

i'm not familiar trigonometry understand needs done. have thought tangent needed third dimensions, i'm lost on how fourth dimension.

can point me articles me understand, google isn't helping me (but i'm using incorrect search terms).

your question tagged c++ it's not clear class library you're using n-dimensional vector math, i'll try answer question purely mathematically, assuming have classes represent n-dimensional vectors , nxn-dimensional matrices (i.e. linear mappings n-dimensional euclidean space onto itself).

generalizing 2d code, algorithm computing spiral mapping becomes like:

  1. translate center of spiral origin (vector subtraction).
  2. get distance of point mapped origin (using n dimensional euclidean distance).
  3. compute rotation angle based on distance (theta = percent * percent * angle;)
  4. map n-1-dimensional sphere centered on origin @ radius onto rotating around center.
  5. translate origin center of spiral.

step 4 stuck. in generalizing (rotational) mappings spheres of n-1 dimensions, 1 must keep in mind hairy ball theorem, states:

there no nonvanishing continuous tangent vector field on even-dimensional n-spheres.

what means that, odd-dimensional vector spaces (i.e. dimensional embedded spheres), there's going @ least 1 visible fixed point in spiral mapping, , cannot avoided. in case, since using rotational mappings, there two fixed points, 1 each selected axis of rotation intersects n-1-sphere.

now, n-dimensional spiral mapping between first 2 dimensions in n-dimensional euclidean space going (as nxn linear transformation matrix):

    ⎡cos(θ)   −sin(θ)    0     .     0⎤     ⎢sin(θ)    cos(θ)          .      ⎢ s = ⎢  0          0      1     .     0⎢     ⎢  .          .      .     .      ⎢     ⎣  0          0                  1⎦ 

one can compose spiral transformations between subsequent pairs of axes following nxn linear transformation matrix:

    ⎡cos(θ)   −sin(θ)     0         0                  ⎤     ⎢sin(θ)    cos(θ)     0         0                  ⎢     ⎢  0         0      cos(θ)   −sin(θ)               ⎢ s = ⎢  0         0      sin(θ)    cos(θ)               ⎢     ⎢                                      .           ⎢     ⎢                                            .     ⎢     ⎣                                                 1⎦ 

notice trailing 1 in final cell? that's there when n-dimensional space has odd number of dimensions, and, hairy ball theorem, can't dispensed with.

in 3 dimensions, becomes spiral around z axis:

    ⎡cos(θ)   −sin(θ)      0⎤ s = ⎢sin(θ)    cos(θ)      0⎢     ⎣   0         0        1⎦ 

thus if o center of spiral , p point transform, overall transform be:

newp = o + s(p - o) 

if prefer spiral around different axis, construct rotational matrix r taking axis z axis, overall spiral matrix become (r⁻¹)*s*r. create rotation matrix r, see e.g. rotating 1 3-vector another.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -