static public GE_Vector GetVector(GE_Point ptFrom, GE_Point ptTo) { GE_Vector v = new GE_Vector(ptTo.X - ptFrom.X, ptTo.Y - ptFrom.Y); v.normalize(); return(v); }
public void set(GE_Point ptStart, GE_Point ptEnd) { m_StartPoint = new GE_Point(ptStart.X, ptStart.Y); m_EndPoint = new GE_Point(ptEnd.X, ptEnd.Y); m_Radiu = 0; m_Kind = 0; }
static public GE_Vector GetVectorByAngle(double dAngle) { GE_Point pt1 = new GE_Point(0, 0); GE_Point pt2 = AcGePolar(pt1, dAngle, 10); return(GetVector(pt1, pt2)); }
static public List <GE_Point> ExplodeArc(GE_Point ptCenter, double dRadiu, double dAngleStart, double dAngleEnd, double dStep) { List <GE_Point> ayResult = new List <GE_Point>(); double dAng = Mid_angle(dAngleStart, dAngleEnd); double dLength = dAng * dRadiu; int iNums = (int)(dLength / dStep); if (iNums < 16) { iNums = 16; } double dAngBase = dAngleStart; GE_Point px; int i; if (iNums != 0) { dAng = dAng / iNums; for (i = 0; i < iNums; i++) { px = AcGePolar(ptCenter, dAngBase, dRadiu); ayResult.Add(px); dAngBase = dAngBase + dAng; } } else { px = AcGePolar(ptCenter, dAngleStart, dRadiu); ayResult.Add(px); } px = AcGePolar(ptCenter, dAngleEnd, dRadiu); ayResult.Add(px); return(ayResult); }
static public bool GetArcByPoint(GE_Point pt1, GE_Point pt2, GE_Point pt3, out GE_Point ptCenter) { bool bRet = false; ptCenter = new GE_Point(); GE_Line lin1 = new GE_Line(); GE_Line lin2 = new GE_Line(); GE_Point ptM1 = Geo.AcGeMidPoint(pt1, pt2); GE_Point ptM2 = Geo.AcGeMidPoint(pt2, pt3); GE_Vector vp = Geo.GetVector(pt1, pt2); vp.RotateBy(PI2); lin1.set(ptM1, ptM1 + vp * 100.0); vp = Geo.GetVector(pt2, pt3); vp.RotateBy(PI2); lin2.set(ptM2, ptM2 + vp * 100.0); GE_Point ptCen1, ptCen2; int nRet = lin1.intersectWith(lin2, out ptCen1, out ptCen2); if (nRet > 0) { ptCenter = ptCen1; bRet = true; } return(bRet); }
public GE_Point PerpendPoint(GE_Point pt) { GE_Point ptRet; if (m_Kind == 1) { GE_Vector v = Geo.GetVector(m_CenterPoint, pt); ptRet = m_CenterPoint + v * m_Radiu; } else { double dL = Length(); List <GE_Point> ayPoints = new List <GE_Point>(); ayPoints.Add(m_StartPoint); ayPoints.Add(m_EndPoint); ayPoints.Add(pt); double dArea = Geo.AreaRange(ayPoints); double dDist = dArea * 2 / dL; GE_Vector vp = Vector(); if (Geo.AcGePosition(m_StartPoint, m_EndPoint, pt) > 0) { vp.RotateBy(Geo.PI2); } else { vp.RotateBy(-Geo.PI2); } ptRet = pt + vp * dDist; } return(ptRet); }
static public void Exchange_point(ref GE_Point pt1, ref GE_Point pt2) { GE_Point pt = new GE_Point(pt1.X, pt1.Y); pt1 = pt2; pt2 = pt; }
public void set(GE_Point ptCenter, GE_Point ptStart, GE_Point ptEnd) { m_StartPoint = new GE_Point(ptStart.X, ptStart.Y); m_EndPoint = new GE_Point(ptEnd.X, ptEnd.Y); m_CenterPoint = new GE_Point(ptCenter.X, ptCenter.Y); m_Radiu = m_CenterPoint.distanceTo(m_StartPoint); m_Kind = 1; }
static public double AcGePosition(GE_Point p1, GE_Point p2, GE_Point p) { double x, y, x1, y1, x2, y2, ret; x = p.X; y = p.Y; x1 = p1.X; y1 = p1.Y; x2 = p2.X; y2 = p2.Y; ret = x * y1 + x1 * y2 + x2 * y - x2 * y1 - x1 * y - x * y2; return(ret); }
//圆心ptCen,点p1到p2的弧长(逆时针,半径为ptCen到p1的距离) static public double GetArcLengthByPoint(GE_Point ptCen, GE_Point p1, GE_Point p2) { double dRad, dAng1, dAng2; dRad = ptCen.distanceTo(p1); dAng1 = GetAngleByPoint(ptCen, p1); dAng2 = GetAngleByPoint(ptCen, p2); dAng1 = Mid_angle(dAng1, dAng2); return(dRad * dAng1); }
static public bool GetExtents(List <GE_Point> ayPt, out GE_Point ptMin, out GE_Point ptMax) { bool bRet = false; int i; ptMin = new GE_Point(); ptMax = new GE_Point(); if (ayPt != null && ayPt.Count > 0) { ptMin = new GE_Point(ayPt[0]); ptMax = new GE_Point(ayPt[0]); for (i = 1; i < ayPt.Count; i++) { ptMin.X = Math.Min(ptMin.X, ayPt[i].X); ptMin.Y = Math.Min(ptMin.Y, ayPt[i].Y); ptMax.X = Math.Max(ptMax.X, ayPt[i].X); ptMax.Y = Math.Max(ptMax.Y, ayPt[i].Y); } bRet = true; } return(bRet); }
/// <summary> /// /// </summary> /// <param name="lin"></param> /// <param name="ptInt1"></param> /// <param name="ptInt2"></param> /// <returns></returns> public int intersectWith(GE_Line lin, out GE_Point ptInt1, out GE_Point ptInt2) { int nRet = 0; ptInt1 = new GE_Point(0, 0); ptInt2 = new GE_Point(0, 0); double A, B, a, b, c, d, P, Q, AA, BB, CC, X1, X2, Y1, Y2; double u; if (m_Kind == 0 && lin.m_Kind == 0) { PointF point1 = new PointF((float)m_StartPoint.X, (float)m_StartPoint.Y); PointF point2 = new PointF((float)m_EndPoint.X, (float)m_EndPoint.Y); PointF point3 = new PointF((float)lin.m_StartPoint.X, (float)lin.m_StartPoint.Y); PointF point4 = new PointF((float)lin.m_EndPoint.X, (float)lin.m_EndPoint.Y); PointF pointResult; if (GetIntersection(point1, point2, point3, point4, out pointResult)) { ptInt1.X = pointResult.X; ptInt1.Y = pointResult.Y; nRet = 1; } //double x11, y11, x12, y12, x21, y21, x22, y22; //x11 = m_StartPoint.X; //y11 = m_StartPoint.Y; //x12 = m_EndPoint.X; //y12 = m_EndPoint.Y; //x21 = lin.m_StartPoint.X; //y21 = lin.m_StartPoint.Y; //x22 = lin.m_EndPoint.X; //y22 = lin.m_EndPoint.Y; //u = (x11 - x21) / ((x22 - x21) - (x12 - x11)); //ptInt1.X = x11 + u * (x12 - x11); //ptInt1.Y = y11 + u * (y12 - y11); //nRet = 1; } else if (m_Kind == 1 && lin.m_Kind == 1) { A = m_CenterPoint.distanceTo(m_StartPoint); B = lin.m_CenterPoint.distanceTo(lin.m_StartPoint); a = m_CenterPoint.X; b = m_CenterPoint.Y; c = lin.m_CenterPoint.X; d = lin.m_CenterPoint.Y; P = ((A * A - B * B) - (a * a + b * b - c * c - d * d)) / (2 * d - 2 * b); Q = (c - a) / (d - b); AA = 1 + Q * Q; BB = 2 * b * Q - 2 * P * Q - 2 * a; CC = P * P - 2 * b * P - A * A + a * a + b * b; if (BB * BB - 4 * AA * CC > 0) { X1 = (BB * -1 + Math.Sqrt(BB * BB - 4 * AA * CC)) / (2 * AA); X2 = (BB * -1 - Math.Sqrt(BB * BB - 4 * AA * CC)) / (2 * AA); Y1 = P - Q * X1; Y2 = P - Q * X2; ptInt1.X = X1; ptInt1.Y = Y1; ptInt2.X = X2; ptInt2.Y = Y2; nRet = 2; } else { nRet = 0; } } return(nRet); }
static public GE_Point AcGeMidPoint(GE_Point pt1, GE_Point pt2) { GE_Point pt = new GE_Point((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2); return(pt); }
static public double DistanceTo(GE_Point pt1, GE_Point pt2) { return(Math.Sqrt((pt2.X - pt1.X) * (pt2.X - pt1.X) + (pt2.Y - pt1.Y) * (pt2.Y - pt1.Y))); }
public GE_Point(GE_Point p) { m_X = p.X; m_Y = p.Y; }
//如果P1到P2到P3为顺时针,则返回1,否则返回0 static public int AcGeClock(GE_Point p1, GE_Point p2, GE_Point p3) { double ang1, ang2; int v; ang1 = GetAngle(p1, p2); ang2 = GetAngle(p2, p3); if ((ang1 < Math.PI) || (Math.Abs(ang1 - Math.PI) < 0.0000001)) { if ((ang2 < Math.PI) || (Math.Abs(ang2 - Math.PI) < 0.0000001)) { if (ang2 > ang1) { v = 0; } else { v = 1; } } else { ang1 = ang1 + Math.PI; if (ang2 > ang1) { v = 1; } else { v = 0; } } } else { if ((ang2 < Math.PI) || (Math.Abs(ang2 - Math.PI) < 0.0000001)) { ang1 = ang1 - Math.PI; if (ang2 > ang1) { v = 1; } else { v = 0; } } else { if (ang2 > ang1) { v = 0; } else { v = 1; } } } return(v); }
public double distanceTo(GE_Point pt) { GE_Point ptPerp = PerpendPoint(pt); return(pt.distanceTo(ptPerp)); }
static public double GetAngleByPoint(GE_Point ptFrom, GE_Point ptTo) { GE_Vector v = GetVector(ptFrom, ptTo); return(v.GetAngle()); }
public double distanceTo(GE_Point pt) { return(Math.Sqrt((pt.X - m_X) * (pt.X - m_X) + (pt.Y - m_Y) * (pt.Y - m_Y))); }
static public GE_Point AcGePolar(GE_Point pt, double dAngle, double dRadiu) { GE_Point ptResult = new GE_Point(pt.X + (float)(dRadiu * Math.Cos(dAngle)), pt.Y + (float)(dRadiu * Math.Sin(dAngle))); return(ptResult); }