//drawing related properties public Vector BalancingVector(bool forLabelPlacement = false) { Vector vsumVector = BasicGeometry.ScreenNorth; if (Bonds.Any()) { double sumOfLengths = 0; foreach (var bond in Bonds) { Vector v = bond.OtherAtom(this).Position - this.Position; if (forLabelPlacement) { // Multiply by bond order to bias away from double or triple bonds double order = bond.OrderValue.Value; if (order > 0.1) { v = v * bond.OrderValue.Value; } } sumOfLengths += v.Length; vsumVector += v; } // Set tiny amount as 10% of average bond length double tinyAmount = sumOfLengths / Bonds.Count() * 0.1; double xy = vsumVector.Length; // Is resultant vector is big enough for us to use? if (xy >= tinyAmount) { // Get vector in opposite direction vsumVector = -vsumVector; vsumVector.Normalize(); } else { // Get vector of first bond Vector vector = Bonds.First().OtherAtom(this).Position - Position; if (Bonds.Count() == 2) { // Get vector at right angles vsumVector = vector.Perpendicular(); vsumVector = -vsumVector; } else { // Get vector in opposite direction vsumVector = -vector; } vsumVector.Normalize(); } } //Debug.WriteLine($"Atom {Id} Resultant Balancing Vector Angle is {Vector.AngleBetween(BasicGeometry.ScreenNorth, vsumVector)}"); return(vsumVector); }
public CompassPoints GetDefaultHOrientation() { if (ImplicitHydrogenCount >= 1) { if (!Bonds.Any()) { return(CompassPoints.East); } else if (Bonds.Count() == 1) { var angle = Vector.AngleBetween(BasicGeometry.ScreenNorth, Bonds.First().OtherAtom(this).Position - Position); int clockDirection = BasicGeometry.SnapToClock(angle); if (clockDirection == 0 || clockDirection == 6) { return(CompassPoints.East); } else if (clockDirection >= 6 && clockDirection <= 11) { return(CompassPoints.East); } else { return(CompassPoints.West); } } else { double baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth, BalancingVector(true)); return(BasicGeometry.SnapTo4NESW(baFromNorth)); } } return(CompassPoints.East); }