public AnchoringSet FindAnchoringSet(IList <TUICircle> circles, float axisLenght, float locationThreshold) { float minimunLength = axisLenght - locationThreshold; float maximunLenght = axisLenght + locationThreshold; double verifyLength = Math.Sqrt(2 * Math.Pow(axisLenght, 2)); foreach (TUICircle circle in circles) { //if (this == circle || circle.Grouped) if (this == circle) { continue; } double distance = GetDistance(this.Circle.Center, circle.Circle.Center); if (distance < minimunLength || distance > maximunLenght) { continue; } //this circle is a the expected distance, so we assume it's the RightAnchor // so we try to find the bottom anchor TUICircle rightAnchor = circle; double angle = GetAngle(this.Circle.Center, rightAnchor.Circle.Center); PointF centerBottomAnchor = GetPointInCircunference(this.Circle.Center, (int)(angle - 90), axisLenght); TUICircle bottomAnchor = GetCircleAt(centerBottomAnchor, circles, locationThreshold); if (bottomAnchor == null) { continue; } PointF centerVerifyAnchor = GetPointInCircunference(this.Circle.Center, (int)(angle + 45), verifyLength); TUICircle verifyAnchor = GetCircleAt(centerVerifyAnchor, circles, locationThreshold); if (verifyAnchor != null) { continue; } this.IsPivot = true; this.Grouped = true; rightAnchor.Grouped = true; bottomAnchor.Grouped = true; AnchoringSet set = new AnchoringSet(); set.Angle = angle - 180; set.Pivot = this; set.RightAnchor = rightAnchor; set.BottomAnchor = bottomAnchor; set.VerifyAnchor = centerVerifyAnchor; return(set); } return(null); }
private PointF CalculatePointFromLenghts(double lenghtToRightAnchor, double lenghtToBottonAnchor) { double alpha = 180 - Angle; double beta = 90 - alpha; double rX, bX; double rY, bY; rX = lenghtToRightAnchor * Math.Cos(TUICircle.DegreeToRadian(alpha)); rY = lenghtToRightAnchor * Math.Sin(TUICircle.DegreeToRadian(alpha)); bX = lenghtToBottonAnchor * Math.Cos(TUICircle.DegreeToRadian(beta)); bY = lenghtToBottonAnchor * Math.Sin(TUICircle.DegreeToRadian(beta)); double calculatedX = Pivot.Circle.Center.X + rX - bX; double calculatedY = Pivot.Circle.Center.Y - rY - bY; return(new PointF((float)calculatedX, (float)calculatedY)); }