PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ vector_rotate()

void vector_rotate ( const POINT3D v1,
const POINT3D v2,
double  angle,
POINT3D n 
)

Rotates v1 through an angle (in radians) within the plane defined by v1/v2, returns the rotated vector in n.

Definition at line 542 of file lwgeodetic.c.

References normalize(), unit_normal(), POINT3D::x, POINT3D::y, and POINT3D::z.

Referenced by test_vector_rotate().

543 {
544  POINT3D u;
545  double cos_a = cos(angle);
546  double sin_a = sin(angle);
547  double uxuy, uyuz, uxuz;
548  double ux2, uy2, uz2;
549  double rxx, rxy, rxz, ryx, ryy, ryz, rzx, rzy, rzz;
550 
551  /* Need a unit vector normal to rotate around */
552  unit_normal(v1, v2, &u);
553 
554  uxuy = u.x * u.y;
555  uxuz = u.x * u.z;
556  uyuz = u.y * u.z;
557 
558  ux2 = u.x * u.x;
559  uy2 = u.y * u.y;
560  uz2 = u.z * u.z;
561 
562  rxx = cos_a + ux2 * (1 - cos_a);
563  rxy = uxuy * (1 - cos_a) - u.z * sin_a;
564  rxz = uxuz * (1 - cos_a) + u.y * sin_a;
565 
566  ryx = uxuy * (1 - cos_a) + u.z * sin_a;
567  ryy = cos_a + uy2 * (1 - cos_a);
568  ryz = uyuz * (1 - cos_a) - u.x * sin_a;
569 
570  rzx = uxuz * (1 - cos_a) - u.y * sin_a;
571  rzy = uyuz * (1 - cos_a) + u.x * sin_a;
572  rzz = cos_a + uz2 * (1 - cos_a);
573 
574  n->x = rxx * v1->x + rxy * v1->y + rxz * v1->z;
575  n->y = ryx * v1->x + ryy * v1->y + ryz * v1->z;
576  n->z = rzx * v1->x + rzy * v1->y + rzz * v1->z;
577 
578  normalize(n);
579 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:584
double y
Definition: liblwgeom.h:342
double x
Definition: liblwgeom.h:342
double z
Definition: liblwgeom.h:342
void unit_normal(const POINT3D *P1, const POINT3D *P2, POINT3D *normal)
Calculates the unit normal to two vectors, trying to avoid problems with over-narrow or over-wide cas...
Definition: lwgeodetic.c:510
Here is the call graph for this function:
Here is the caller graph for this function: