public static UnitPoint GetBulgeCenter(UnitPoint vertex, UnitPoint cutoffPoint, UnitPoint cutoffPoint2, double radius) { UnitPoint midPoint = HitUtil.LineMidpoint(cutoffPoint, cutoffPoint2); double midAngle = HitUtil.LineAngleR(vertex, midPoint, 0); double sideLen = GetDistanceBetweenVertexAndCutoffPoint(radius, midAngle * 2); double vertexToCenter = radius * radius + sideLen * sideLen; UnitPoint center = HitUtil.LineEndPoint(vertex, midAngle, vertexToCenter); return(center); }
private UnitPoint MidPoint(UnitPoint p1, UnitPoint p2, UnitPoint hitPoint) { UnitPoint midPoint = HitUtil.LineMidpoint(p1, p2); if (HitUtil.CircleHitPoint(midPoint, UCCanvas.GetThresholdWidth(), hitPoint)) { return(midPoint); } return(UnitPoint.Empty); }
private UnitPoint MidPoint(ICanvas canvas, UnitPoint P1, UnitPoint P2, UnitPoint hitPoint) { UnitPoint midPoint = HitUtil.LineMidpoint(P1, P2); float thresholdWidth = UCCanvas.GetThresholdWidth(); if (HitUtil.CircleHitPoint(midPoint, thresholdWidth, hitPoint)) { return(midPoint); } return(UnitPoint.Empty); }
UnitPoint MidPoint(ICanvas canvas, UnitPoint p1, UnitPoint p2, UnitPoint hitpoint) { UnitPoint mid = HitUtil.LineMidpoint(p1, p2); float thWidth = ThresholdWidth(canvas, Width); if (HitUtil.CircleHitPoint(mid, thWidth, hitpoint)) { return(mid); } return(UnitPoint.Empty); }
/// <summary> /// 获取中点,返回四边中点 /// </summary> /// <param name="canvas"></param> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="hitpoint"></param> /// <returns></returns> UnitPoint MidPoint(ICanvas canvas, UnitPoint p1, UnitPoint p2, UnitPoint hitpoint) { //MessageBox.Show("Mid"); UnitPoint p3 = new UnitPoint(p1.X, p2.Y); UnitPoint p4 = new UnitPoint(p2.X, p1.Y); //UnitPoint mid1 = HitUtil.LineMidpoint(p1, p3); //UnitPoint mid2 = HitUtil.LineMidpoint(p1, p4); //UnitPoint mid3 = HitUtil.LineMidpoint(p3, p2); //UnitPoint mid4 = HitUtil.LineMidpoint(p4, p2); //UnitPoint mid5 = HitUtil.LineMidpoint(p1, p2); UnitPoint mid6 = HitUtil.LineMidpoint(p3, p3); UnitPoint mid7 = HitUtil.LineMidpoint(p4, p4); float thWidth = ThresholdWidth(canvas, Width); Console.WriteLine("thWidth" + thWidth + ""); //if (HitUtil.CircleHitPoint(mid1, thWidth, hitpoint)) //{ // return mid1; //} //if (HitUtil.CircleHitPoint(mid2, thWidth, hitpoint)) //{ // return mid2; //} //if (HitUtil.CircleHitPoint(mid3, thWidth, hitpoint)) //{ // return mid3; //} //if (HitUtil.CircleHitPoint(mid4, thWidth, hitpoint)) //{ // return mid4; //} //if (HitUtil.CircleHitPoint(mid5, thWidth, hitpoint)) //{ // return mid5; //} if (HitUtil.CircleHitPoint(mid6, thWidth, hitpoint)) { return(mid6); } if (HitUtil.CircleHitPoint(mid7, thWidth, hitpoint)) { return(mid7); } return(UnitPoint.Empty); }
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point) { m_lastPoint = point; if (m_curPoint == eCurrentPoint.p1) { m_p1 = point; Center = point; return; } if (m_curPoint == eCurrentPoint.p2) { StartAngle = 0; EndAngle = 360; Center = HitUtil.LineMidpoint(m_p1, point); m_radius = (float)HitUtil.Distance(m_center, point); return; } if (m_curPoint == eCurrentPoint.center) { Center = point; } if (m_curPoint == eCurrentPoint.radius) { //StartAngle = 0; //EndAngle = 360; m_radius = (float)HitUtil.Distance(m_center, point); } double angleToRound = 0; if (Control.ModifierKeys == Keys.Control) { angleToRound = HitUtil.DegressToRadians(45); } if (m_curPoint == eCurrentPoint.startAngle) { StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, point, angleToRound)); } if (m_curPoint == eCurrentPoint.endAngle) { EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, point, angleToRound)); } }
/// <summary> /// 根据给定类型返回点的快照信息 /// </summary> /// <param name="canvas"></param> /// <param name="point"></param> /// <param name="otherobj"></param> /// <param name="runningsnaptypes"></param> /// <param name="usersnaptype"></param> /// <returns></returns> ISnapPoint IDrawObject.SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype) { float thWidth = ThresholdWidth(canvas, Width); if (runningsnaptypes != null) { foreach (Type snaptype in runningsnaptypes) { if (snaptype == typeof(VertextSnapPoint)) { if (HitUtil.CircleHitPoint(m_p1, thWidth, point)) { return(new VertextSnapPoint(canvas, this, m_p1)); } if (HitUtil.CircleHitPoint(m_p2, thWidth, point)) { return(new VertextSnapPoint(canvas, this, m_p2)); } } if (snaptype == typeof(MidpointSnapPoint)) { UnitPoint p = MidPoint(canvas, m_p1, m_p2, point); if (p != UnitPoint.Empty) { return(new MidpointSnapPoint(canvas, this, p)); } } if (snaptype == typeof(IntersectSnapPoint)) { Rectangle rectangle = Utils.FindObjectTypeInList(this, otherobj, typeof(Rectangle)) as Rectangle; if (rectangle == null) { continue; } UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, rectangle.m_p1, rectangle.m_p2); if (p != UnitPoint.Empty) { return(new IntersectSnapPoint(canvas, this, p)); } } } return(null); } if (usersnaptype == typeof(MidpointSnapPoint)) { return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2))); } if (usersnaptype == typeof(IntersectSnapPoint)) { Rectangle rectangle = Utils.FindObjectTypeInList(this, otherobj, typeof(Rectangle)) as Rectangle; if (rectangle == null) { return(null); } UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, rectangle.m_p1, rectangle.m_p2); if (p != UnitPoint.Empty) { return(new IntersectSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(VertextSnapPoint)) { double d1 = HitUtil.Distance(point, m_p1); double d2 = HitUtil.Distance(point, m_p2); if (d1 <= d2) { return(new VertextSnapPoint(canvas, this, m_p1)); } return(new VertextSnapPoint(canvas, this, m_p2)); } if (usersnaptype == typeof(NearestSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point); if (p != UnitPoint.Empty) { return(new NearestSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(PerpendicularSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point); if (p != UnitPoint.Empty) { return(new PerpendicularSnapPoint(canvas, this, p)); } } return(null); }
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint unitPoint, List <IDrawObject> drawObjects, Type[] runningSnapTypes, Type userSnapType) { float thWidth = UCCanvas.GetThresholdWidth(); if (runningSnapTypes != null) { foreach (Type snaptype in runningSnapTypes) { if (snaptype == typeof(VertextSnapPoint)) { if (HitUtil.CircleHitPoint(this.P1, thWidth, unitPoint)) { return(new VertextSnapPoint(canvas, this, this.P1)); } if (HitUtil.CircleHitPoint(this.P2, thWidth, unitPoint)) { return(new VertextSnapPoint(canvas, this, this.P2)); } } if (snaptype == typeof(MidpointSnapPoint)) { UnitPoint p = MidPoint(canvas, this.P1, this.P2, unitPoint); if (p != UnitPoint.Empty) { return(new MidpointSnapPoint(canvas, this, p)); } } if (snaptype == typeof(IntersectSnapPoint)) { Line otherline = Utils.Utils.FindObjectTypeInList(this, drawObjects, typeof(Line)) as Line; if (otherline == null) { continue; } UnitPoint p = HitUtil.LinesIntersectPoint(this.P1, this.P2, otherline.P1, otherline.P2); if (p != UnitPoint.Empty) { return(new IntersectSnapPoint(canvas, this, p)); } } } return(null); } if (userSnapType == typeof(MidpointSnapPoint)) { return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(this.P1, this.P2))); } if (userSnapType == typeof(IntersectSnapPoint)) { Line otherline = Utils.Utils.FindObjectTypeInList(this, drawObjects, typeof(Line)) as Line; if (otherline == null) { return(null); } UnitPoint p = HitUtil.LinesIntersectPoint(this.P1, this.P2, otherline.P1, otherline.P2); if (p != UnitPoint.Empty) { return(new IntersectSnapPoint(canvas, this, p)); } } if (userSnapType == typeof(VertextSnapPoint)) { double d1 = HitUtil.Distance(unitPoint, this.P1); double d2 = HitUtil.Distance(unitPoint, this.P2); if (d1 <= d2) { return(new VertextSnapPoint(canvas, this, this.P1)); } return(new VertextSnapPoint(canvas, this, this.P2)); } if (userSnapType == typeof(NearestSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint); if (p != UnitPoint.Empty) { return(new NearestSnapPoint(canvas, this, p)); } } if (userSnapType == typeof(PerpendicularSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint); if (p != UnitPoint.Empty) { return(new PerpendicularSnapPoint(canvas, this, p)); } } return(null); }