16 #ifndef INCLUDED_numeric_xyz_functions_hh
17 #define INCLUDED_numeric_xyz_functions_hh
63 template<
typename T >
76 template<
typename T >
85 center_of_mass += *it;
87 center_of_mass /= coords.size();
93 template<
typename T >
108 template<
typename T >
123 template<
typename T >
138 template<
typename T >
153 template<
typename T >
190 template<
typename T >
202 template<
typename T >
222 template<
typename T >
245 template<
typename T >
270 template<
typename T >
295 template<
typename T >
324 template<
typename T >
355 template<
typename T >
366 static T const ZERO( 0 );
377 if ( ( b == ZERO ) ) {
381 T const x = -
dot( a, c ) + (
dot( a, b ) *
dot( b, c ) );
384 angle = ( ( y != ZERO ) || ( x != ZERO ) ? std::atan2( y, x ) : ZERO );
407 template<
typename T >
432 template<
typename T >
458 template<
typename T >
483 template<
typename T >
505 ) {
dihedral(p1, p2, p3, p4, angle); }
510 template<
typename T >
530 ) {
return dihedral(p1, p2, p3, p4); }
535 template<
typename T >
545 template<
typename T >
555 T const sin_theta( std::sin( theta ) );
556 T const cos_theta( std::cos( theta ) );
560 R.
xx_ += cos_theta; R.
xy_ -= sin_theta * n.
z_; R.
xz_ += sin_theta * n.
y_;
561 R.
yx_ += sin_theta * n.
z_; R.
yy_ += cos_theta; R.
yz_ -= sin_theta * n.
x_;
562 R.
zx_ -= sin_theta * n.
y_; R.
zy_ += sin_theta * n.
x_; R.
zz_ += cos_theta;
569 template<
typename T >
582 template<
typename T >
595 template<
typename T >
602 T const sin_theta( std::sin( theta ) );
603 T const cos_theta( std::cos( theta ) );
606 T( 1 ),
T( 0 ),
T( 0 ),
607 T( 0 ), cos_theta, -sin_theta,
608 T( 0 ), sin_theta, cos_theta
614 template<
typename T >
626 template<
typename T >
638 template<
typename T >
645 T const sin_theta( std::sin( theta ) );
646 T const cos_theta( std::cos( theta ) );
649 cos_theta,
T( 0 ), sin_theta,
650 T( 0 ),
T( 1 ),
T( 0 ),
651 -sin_theta,
T( 0 ), cos_theta
657 template<
typename T >
669 template<
typename T >
681 template<
typename T >
688 T const sin_theta =
static_cast< T > ( std::sin( theta ) );
689 T const cos_theta =
static_cast< T > ( std::cos( theta ) );
692 cos_theta, -sin_theta,
T( 0 ),
693 sin_theta, cos_theta,
T( 0 ),
694 T( 0 ) ,
T( 0 ),
T( 1 )
700 template<
typename T >
712 template<
typename T >
724 template<
typename T >
736 T cb1 = X1[2], sb1 = sqrt(1-(X1[2]*X1[2]));
737 T Rg1 = sqrt((X1[0]*X1[0])+(X1[1]*X1[1]));
738 T cg1 = X1[1]/Rg1, sg1 = X1[0]/Rg1;
740 T cb2 = X2[2], sb2 = sqrt(1-(X2[2]*X2[2]));
741 T Rg2 = sqrt((X2[0]*X2[0])+(X2[1]*X2[1]));
742 T cg2 = X2[1]/Rg2, sg2 = X2[0]/Rg2;
745 R1gb.
xx( cg1 ); R1gb.
xy(cb1*sg1); R1gb.
xz(sb1*sg1);
746 R1gb.
yx(-sg1 ); R1gb.
yy(cb1*cg1); R1gb.
yz(sb1*cg1);
747 R1gb.
zx( 0 ); R1gb.
zy(-sb1) ; R1gb.
zz(cb1);
749 R2gb.
xx( cg2 ); R2gb.
xy(cb2*sg2); R2gb.
xz(sb2*sg2);
750 R2gb.
yx(-sg2 ); R2gb.
yy(cb2*cg2); R2gb.
yz(sb2*cg2);
751 R2gb.
zx( 0 ); R2gb.
zy(-sb2) ; R2gb.
zz(cb2);
762 T Ra1 = sqrt((RgbA1[0]*RgbA1[0])+(RgbA1[1]*RgbA1[1]));
763 T Ra2 = sqrt((RgbA2[0]*RgbA2[0])+(RgbA2[1]*RgbA2[1]));
764 T ca1 = RgbA1[1]/Ra1, sa1 = RgbA1[0]/Ra1;
765 T ca2 = RgbA2[1]/Ra2, sa2 = RgbA2[0]/Ra2;
768 R1.
xx( -sa1*cb1*sg1 + ca1*cg1 ); R1.
xy( ca1*cb1*sg1 + sa1*cg1 ); R1.
xz( sb1*sg1 );
769 R1.
yx( -sa1*cb1*cg1 - ca1*sg1 ); R1.
yy( ca1*cb1*cg1 - sa1*sg1 ); R1.
yz( sb1*cg1 );
770 R1.
zx( sa1*sb1 ); R1.
zy( -ca1*sb1 ); R1.
zz( cb1 );
772 R2.
xx( -sa2*cb2*sg2 + ca2*cg2 ); R2.
xy( ca2*cb2*sg2 + sa2*cg2 ); R2.
xz( sb2*sg2 );
773 R2.
yx( -sa2*cb2*cg2 - ca2*sg2 ); R2.
yy( ca2*cb2*cg2 - sa2*sg2 ); R2.
yz( sb2*cg2 );
774 R2.
zx( sa2*sb2 ); R2.
zy( -ca2*sb2 ); R2.
zz( cb2 );
787 template<
typename T >
799 static T const ZERO( 0 );
800 static T const ONE( 1 );
801 static T const TWO( 2 );
806 if ( cos_theta > -ONE + tolerance && cos_theta < ONE - tolerance ) {
807 return acos( cos_theta );
808 }
else if ( cos_theta >= ONE - tolerance ) {
820 template<
typename T >
832 static T const ZERO( 0 );
833 static T const ONE( 1 );
834 static T const TWO( 2 );
839 if ( cos_theta > -ONE + tolerance && cos_theta < ONE - tolerance ) {
842 T x = ( R.
zy_ > R.
yz_ ? ONE : -ONE ) *
843 sqrt(
max( ZERO, ( R.
xx_ - cos_theta ) / ( ONE - cos_theta ) ) );
844 T y = ( R.
xz_ > R.
zx_ ? ONE : -ONE ) *
845 sqrt(
max( ZERO, ( R.
yy_ - cos_theta ) / ( ONE - cos_theta ) ) );
846 T z = ( R.
yx_ > R.
xy_ ? ONE : -ONE ) *
847 sqrt(
max( ZERO, ( R.
zz_ - cos_theta ) / ( ONE - cos_theta ) ) );
855 theta = acos( cos_theta );
856 assert(
std::abs( x*x + y*y + z*z - 1 ) <=
T( 0.01 ) );
859 }
else if ( cos_theta >= ONE - tolerance ) {
869 if ( nnT.
xx_ > ZERO + tolerance ) {
874 }
else if ( nnT.
yy_ > ZERO + tolerance ) {
882 assert( nnT.
zz_ > ZERO + tolerance );
890 assert(
std::abs( x*x + y*y + z*z - 1 ) <=
T( 0.01 ) );
899 template<
typename T>
915 template<
typename T >
931 int i, j, n_iterations = 0;
933 while ( off > tol ) {
938 assert( n_iterations <= 50 );
954 T const ij_scaled =
std::abs(
T( 100 ) * m(i,j) );
955 if ( ( n_iterations > 4 )
958 m(i,j) = m(j,i) =
T( 0 );
979 template<
typename T >
996 int i, j, n_iterations = 0;
998 while ( off > tol ) {
1003 assert( n_iterations <= 50 );
1019 T const ij_scaled =
std::abs(
T( 100 ) * m(i,j) );
1020 if ( ( n_iterations > 4 )
1023 m(i,j) = m(j,i) =
T( 0 );
1047 template<
typename T >
1055 assert( ( i > 0 ) && ( i <= 3 ) );
1056 assert( ( j > 0 ) && ( j <= 3 ) );
1059 static T const ZERO( 0 );
1060 static T const ONE( 1 );
1062 T const tau = ( m(i,i) - m(j,j) ) / ( 2 * m(i,j) );
1063 T const t = ( tau < ZERO ? -ONE : ONE ) / (
std::abs( tau ) + sqrt( ONE + ( tau * tau ) ) );
1065 T const c = ONE / sqrt( ONE + ( t * t ) );
1069 r(i,i) = c; r(i,j) = -
s;
1070 r(j,i) =
s; r(j,j) = c;
1073 template<
typename T>
1080 spherical.
radius(sqrt((xyz.
x()*xyz.
x())+(xyz.
y()*xyz.
y())+(xyz.
z()*xyz.
z())));
1086 template<
typename T>
1100 template<
typename T>
1117 template<
typename T>
1132 template<
typename T>
1137 assert(input.
size1() == 3);
1149 template<
typename T>
1154 assert(input.
size1() == 3 && input.
size2() == 3);
1164 template<
typename T>
1186 #endif // INCLUDED_numeric_xyz_functions_HH
xyzVector< T > eigenvector_jacobi(xyzMatrix< T > const &a, T const &tol, xyzMatrix< T > &J)
Classic Jacobi algorithm for the eigenvalues and eigenvectors of a real symmetric matrix...
void normalized(xyzVector &a) const
Normalized.
xyzMatrix< T > z_rotation_matrix(T const &theta)
Rotation matrix for rotation about the z axis by an angle in radians.
xyzVector< T > comma_seperated_string_to_xyz(std::string triplet)
convert a string of comma separated values "0.2,0.4,0.3" to an xyzVector
Value const & zz() const
Value zz const.
xyzMatrix< T > y_rotation_matrix_degrees(T const &theta)
Rotation matrix for rotation about the y axis by an angle in degrees.
Value det() const
Determinant.
void angle_radians(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, T &angle)
Plane angle in radians: angle value passed.
void dihedral_radians_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3, xyzVector< double > const &p4, double &angle)
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
static xyzMatrix rows(Value const &xx_a, Value const &xy_a, Value const &xz_a, Value const &yx_a, Value const &yy_a, Value const &yz_a, Value const &zx_a, Value const &zy_a, Value const &zz_a)
Row-ordered value named constructor.
Value magnitude_squared() const
Magnitude squared.
void dihedral_radians(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, xyzVector< T > const &p4, T &angle)
Dihedral (torsion) angle in radians: angle value passed.
xyzVector< T > rotation_axis(xyzMatrix< T > const &R, T &theta)
Transformation from rotation matrix to helical axis of rotation.
Value x_
Coordinates of the 3 coordinate vector.
NumericTraits: Numeric type traits.
xyzMatrix< T > rotation_matrix(xyzVector< T > const &axis, T const &theta)
Rotation matrix for rotation about an axis by an angle in radians.
Value const & z() const
Value z const.
void dihedral(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, xyzVector< T > const &p4, T &angle)
Dihedral (torsion) angle in degrees: angle value passed.
xyzMatrix< T > alignVectorSets(xyzVector< T > A1, xyzVector< T > B1, xyzVector< T > A2, xyzVector< T > B2)
Helper function to find the rotation to optimally transform the vectors A1-B1 to vectors A2-B2...
Value length_squared() const
Length squared.
xyzMatrix & left_multiply_by_transpose(xyzMatrix< U > const &m)
Left multiply by transpose xyzMatrix.
#define runtime_assert(_Expression)
Assert that the condition holds. Evaluated for both debug and release builds.
Value const & radius() const
Value z const.
Value magnitude() const
Magnitude.
Conversions between degrees and radians.
xyzMatrix< T > x_rotation_matrix_radians(T const &theta)
Rotation matrix for rotation about the x axis by an angle in radians.
void jacobi_rotation(xyzMatrix< T > const &m, int const i, int const j, xyzMatrix< T > &r)
Jacobi rotation.
xyzVector< Real > xyz(Real const &r1, Real const &omega1, Real const &t, Real const &dz1, Real const &delta_omega1, Real const &delta_z1)
Returns the x-, y-, and z-coordinates of a point on a helix given r1, omega1, and t...
Value const & yx() const
Value yx const.
Value const & xx() const
Value xx const.
xyzMatrix< T > projection_matrix(xyzVector< T > const &v)
geometric center
utility::vector1< xyzVector< T > > FArray_to_vector_of_xyzvectors(ObjexxFCL::FArray2D< T > const &input)
convert an FArray2D to a vector of xyzVectors
T sin_cos_range(T const &x, T const &tol=T(.001))
Adjust a sine or cosine value to the valid [-1,1] range if within a specified tolerance or exit with ...
utility::vector1< std::string > string_split(std::string const &in, char splitchar)
xyzVector< T > rotation_axis_angle(xyzMatrix< T > const &R)
Transformation from rotation matrix to compact axis-angle representation.
Value const & yz() const
Value yz const.
Value const & yy() const
Value yy const.
void dihedral_degrees(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, xyzVector< T > const &p4, T &angle)
Dihedral (torsion) angle in degrees: angle value passed.
xyzMatrix< T > x_rotation_matrix(T const &theta)
Rotation matrix for rotation about the x axis by an angle in radians.
xyzMatrix< T > z_rotation_matrix_degrees(T const &theta)
Rotation matrix for rotation about the z axis by an angle in degrees.
Fstring::size_type index(Fstring const &s, Fstring const &ss)
First Index Position of a Substring in an Fstring.
ObjexxFCL::FArray2D< T > vector_of_xyzvectors_to_FArray(utility::vector1< xyzVector< T > > const &input)
convert a vector1 of xyzVectors to an FArray2D
xyzMatrix & to_identity()
Set to the identity xyzMatrix.
T const from_string(std::string const &s, T)
Value const & y() const
Value y const.
double angle_degrees_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3)
sphericalVector: Fast spherical-coordinate numeric vector
xyzVector< T > & inplace_product(xyzMatrix< T > const &m, xyzVector< T > &v)
xyzMatrix * xyzVector in-place product
xyzVector< T > & inplace_transpose_product(xyzMatrix< T > const &m, xyzVector< T > &v)
xyzMatrix^T * xyzVector in-place transpose product
xyzMatrix< T > y_rotation_matrix(T const &theta)
Rotation matrix for rotation about the y axis by an angle in radians.
Value trace() const
Trace.
short int max(short int const a, short int const b)
max( short int, short int )
void dihedral_degrees_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3, xyzVector< double > const &p4, double &angle)
T & to_degrees(T &radians)
Degrees from radians.
xyzMatrix< T > x_rotation_matrix_degrees(T const &theta)
Rotation matrix for rotation about the x axis by an angle in degrees.
xyzVector< T > closest_point_on_line(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &q)
xyzMatrix * xyzVector
Fast spherical-coordinate numeric vector.
xyzMatrix< T > y_rotation_matrix_radians(T const &theta)
Rotation matrix for rotation about the y axis by an angle in radians.
T rotation_angle(xyzMatrix< T > const &R)
Transformation from rotation matrix to magnitude of helical rotation.
T abs(T const &x)
std::abs( x ) == | x |
std::vector with 1-based indexing
xyzMatrix< T > rotation_matrix_radians(xyzVector< T > const &axis, T const &theta)
Rotation matrix for rotation about an axis by an angle in radians.
T angle_degrees(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3)
Plane angle in degrees: angle value returned.
void product(ForwardIterator probs1_first, ForwardIterator probs1_last, ForwardIterator probs2_first, ForwardIterator probs2_last)
Multiplies two probability vectors with one another. Probability vectors are assumed to have equal le...
T degrees(T const &radians)
Degrees of radians.
xyzVector< T > center_of_mass(utility::vector1< xyzVector< T > > const &coords)
calculate center of mass for coordinates
xyzMatrix< T > inverse(xyzMatrix< T > const &a)
Value const & zx() const
Value zx const.
Value const & x() const
Value x const.
xyzVector< T > spherical_to_xyz(sphericalVector< T > const &spherical)
xyzTriple< T > cross(xyzTriple< T > const &a, xyzTriple< T > const &b)
Cross product.
xyzVector & normalize()
Normalize.
xyzMatrix< T > rotation_matrix_degrees(xyzVector< T > const &axis, T const &theta)
Rotation matrix for rotation about an axis by an angle in degrees.
T dot_product(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
size_type size1() const
Size of Dimension 1.
Value const & zy() const
Value zy const.
vector1: std::vector with 1-based indexing
xyzMatrix< T > outer_product(xyzVector< T > const &a, xyzVector< T > const &b)
xyzVector xyzVector outer product
sphericalVector< T > xyz_to_spherical(xyzVector< T > const &xyz)
Value xx_
Elements of the 3x3 matrix.
void dihedral_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3, xyzVector< double > const &p4, double &angle)
xyzMatrix< T > z_rotation_matrix_radians(T const &theta)
Rotation matrix for rotation about the z axis by an angle in radians.
numeric::xyzMatrix< T > FArray_to_xyzmatrix(ObjexxFCL::FArray2D< T > const &input)
convert a 3x3 FArray 2D to an xyzMatrix
T radians(T const °rees)
Radians of degrees.
Some std::string helper functions.
Fast (x,y,z)-coordinate numeric vector.
size_type size2() const
Size of Dimension 2.
Value const & theta() const
Value y const.
Value const & xz() const
Value xz const.
Value const & phi() const
Value x const.
Value const & xy() const
Value xy const.
xyzVector< T > eigenvalue_jacobi(xyzMatrix< T > const &a, T const &tol)
Classic Jacobi algorithm for the eigenvalues of a real symmetric matrix.
T dot(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
xyzMatrix & right_multiply_by(xyzMatrix< U > const &m)
Right multiply by xyzMatrix.
ObjexxFCL::FArray2D< T > xyzmatrix_to_FArray(numeric::xyzMatrix< T > const &input)
convert an xyzMatrix to a 3x3 FArray 2D
numeric::xyzVector< core::Real > point
xyzVector< T > transpose_product(xyzMatrix< T > const &m, xyzVector< T > const &v)
xyzMatrix^T * xyzVector product
FArray2D: Fortran-Compatible 2D Array.
double angle_radians_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3)