public static void rotate ( IAtom atom , Point3d p1 , Point3d p2 , double angle ) { double costheta , sintheta ; Point3d r = new Point3d ( ) ; r . x = p2 . x - p1 . x ; r . y = p2 . y - p1 . y ; r . z = p2 . z - p1 . z ; normalize ( r ) ; angle = angle * Math . PI / 180.0 ; costheta = Math . cos ( angle ) ; sintheta = Math . sin ( angle ) ; Point3d p = atom . getPoint3d ( ) ; p . x -= p1 . x ; p . y -= p1 . y ; p . z -= p1 . z ; Point3d q = new Point3d ( 0 , 0 , 0 ) ; q . x += ( costheta + ( 1 - costheta ) * r . x * r . x ) * p . x ; q . x += ( ( 1 - costheta ) * r . x * r . y - r . z * sintheta ) * p . y ; q . x += ( ( 1 - costheta ) * r . x * r . z + r . y * sintheta ) * p . z ; q . y += ( ( 1 - costheta ) * r . x * r . y + r . z * sintheta ) * p . x ; q . y += ( costheta + ( 1 - costheta ) * r . y * r . y ) * p . y ; q . y += ( ( 1 - costheta ) * r . y * r . z - r . x * sintheta ) * p . z ; q . z += ( ( 1 - costheta ) * r . x * r . z - r . y * sintheta ) * p . x ; q . z += ( ( 1 - costheta ) * r . y * r . z + r . x * sintheta ) * p . y ; q . z += ( costheta + ( 1 - costheta ) * r . z * r . z ) * p . z ; q . x += p1 . x ; q . y += p1 . y ; q . z += p1 . z ; atom . setPoint3d ( q ) ; }
Rotates a 3D point about a specified line segment by a specified angle .