Vector2d getRingCenterOfFirstRing ( IRing ring , Vector2d bondVector , double bondLength ) { int size = ring . getAtomCount ( ) ; double radius = bondLength / ( 2 * Math . sin ( ( Math . PI ) / size ) ) ; double newRingPerpendicular = Math . sqrt ( Math . pow ( radius , 2 ) - Math . pow ( bondLength / 2 , 2 ) ) ; /* get the angle between the x axis and the bond vector */ double rotangle = GeometryUtil . getAngle ( bondVector . x , bondVector . y ) ; /* * Add 90 Degrees to this angle, this is supposed to be the new * ringcenter vector */ rotangle += Math . PI / 2 ; return new Vector2d ( Math . cos ( rotangle ) * newRingPerpendicular , Math . sin ( rotangle ) * newRingPerpendicular ) ; }
Calculated the center for the first ring so that it can layed out . Only then all other rings can be assigned coordinates relative to it .