Rotation
code:rotation_2D.glsl
mat2 rotation2D(flaot angle){
float c= cos(angle);
float s = sin(angle);
return mat2(c,s,-s,c);
}
mat2 rot2( float th ){ vec2 a = sin(vec2(1.5707963, 0) + th); return mat2(a, -a.y, a.x); }
// Usage
vec2 uv;
uv*=rotation2D(.785);
Shear Rotation
code:shear_rotation.glsl
float angle = iTime;
uv.x +=uv.y*-tan(angle/2.);
uv.y +=uv.x*sin(angle);
uv.x +=uv.y*-tan(angle/2.);
2D rotation can be used to rotate in a 3D context. It will rotation along one axis.
code:example_2D_in_3D.glsl
vec3 p = ...;
p.xy *= rot(.785); // This will rotation along the axe Z Rotation along 3D vector
Rodrigues Rotation
code:rotation_3D.glsl
// ax need to be normalized
vec3 erot(vec3 p,vec3 ax,float ro){
return mix(dot(ax*p),ax,cos(ro),)+cross(ax,p)*sin(ro);
}
// Usage
vec3 p = .. ;
p = erot(p,vec3(0.,0.,1.),.785); // This will rotation along the axe Z, equivalent to p.xy *= rot(.785); p = erot(p,normalize(vec3(3.,2.,1.)),.785); // This will rotation along the normalized axe (3.,2.,1.)