private Point2d horizontalOffset ( Point2d [ ] points , Turn [ ] turns , Projection projection ) { // Haworth must currently be drawn vertically, I have seen them drawn // slanted but it's difficult to determine which way the projection // is relative if ( projection != Projection . Chair ) return new Point2d ( 0 , 0 ) ; // the atoms either side of a central atom are our reference int offset = chairCenterOffset ( turns ) ; int prev = ( offset + 5 ) % 6 ; int next = ( offset + 7 ) % 6 ; // and the axis formed by these atoms is our horizontal reference which // we normalise double deltaX = points [ prev ] . x - points [ next ] . x ; double deltaY = points [ prev ] . y - points [ next ] . y ; double mag = Math . sqrt ( deltaX * deltaX + deltaY * deltaY ) ; deltaX /= mag ; deltaY /= mag ; // we now ensure the reference always points left to right (presumes no // vertical chairs) if ( deltaX < 0 ) { deltaX = - deltaX ; deltaY = - deltaY ; } // horizontal = <1,0> so the offset if the difference from this return new Point2d ( 1 - deltaX , deltaY ) ; }
Determine the horizontal offset of the projection . This allows projections that are drawn at angle to be correctly interpreted . Currently only projections of chair conformations are considered .