Function geo_nd::vector::rotate_around

source ·
pub fn rotate_around<V: Float, const D: usize>(
    v: [V; D],
    pivot: &[V; D],
    angle: V,
    c0: usize,
    c1: usize
) -> [V; D]
Expand description

Rotate a vector within a plane around a pivot point by the specified angle

The plane of rotation is specified by providing two vector indices for the elements to adjust. For a 2D rotation then the values of c0 and c1 should be 0 and 1.

For a 3D rotation about the Z axis, they should be 0 and 1; for rotation about the Y axis they should be 2 and 0; and for rotation about the X axis they should be 1 and 2.

Examples

use geo_nd::vector;
let a = [3., 4., 5.];
let pivot = [3., 3., 0.];
// Rotate by 90 degress anticlockwise about the Z-axis pivoting on (3,3,0)
assert!( vector::distance_sq( &vector::rotate_around(a, &pivot, (90.0_f32).to_radians(), 0, 1 ), &[2., 3., 5.] ) < 1E-8 );
// Rotate by 90 degress anticlockwise about the X-axis pivoting on (3,3,0)
assert!( vector::distance_sq( &vector::rotate_around(a, &pivot, (90.0_f32).to_radians(), 1, 2 ), &[3., -2., 1.] ) < 1E-8 );