/////////////////////////////////////////////// //////////////////PROPERTIES/////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// ////////////////////METHODS//////////////////// /////////////////////////////////////////////// //////////////TRANSFORM_METHODS//////////////// public void moveTo(GlPointR2 newBelongsPoint) { if (newBelongsPoint == null || newBelongsPoint.isNullPoint()) { return; } if (OnMoveStart != null) { if (!OnMoveStart.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y)) { return; } } if (OnMoving != null) { OnMoving.Invoke(this, this.pointOfLine.X, this.pointOfLine.Y); } GlPointR2 OP = new GlPointR2(this.PointOfLine); this.pointOfLine = newBelongsPoint; if (OnMoved != null) { OnMoved.Invoke(this, OP.X, OP.Y); } }
/////////////INSIDE_BELONGS_METHODS//////////// /////////////////////////////////////////////// ///////////////ADDITIONAL_METHODS////////////// public virtual void AddVertex(GlPointR2 P) { if (P == null || P.isNullPoint()) { return; } if (OnVertexAddingStart != null) { if (!OnVertexAddingStart.Invoke(P)) { return; } } if (OnVertexAdding != null) { OnVertexAdding.Invoke(P); } if (polyCenter == null) { polyCenter = P; } GlPointR2[] copy = this.vertexes; this.vertexes = new GlPointR2[this.vertexes.Length + 1]; Array.Copy(copy, this.vertexes, copy.Length); this.vertexes[this.vertexes.Length - 1] = P; if (OnVertexAdded != null) { OnVertexAdded.Invoke(P); } }
public GlLineR2 getParallel(GlPointR2 P) { if (P == null || this.pointOfLine.isNullPoint() || P.isNullPoint()) { return(null); } return(new GlLineR2(P, this.DirectVector)); }
public override bool isPointBelongs(GlPointR2 P) { if (P == null || P.isNullPoint()) { return(false); } GlPointR2 TP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center); return(Math.Abs(TP.X - RealHalfAixis * Math.Sqrt(TP.Y * TP.Y + Math.Pow(AdditionalHalfAixis, 2.0)) / AdditionalHalfAixis) < FAULT); }
public override bool isPointBelongs(GlPointR2 P) { if (P == null || P.isNullPoint()) { return(false); } GlPointR2 LineMovedPoint = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY)); return(Math.Abs(Math.Pow(LineMovedPoint.X / this.RadA, 2.0) + Math.Pow(LineMovedPoint.Y / this.RadB, 2.0) - 1) < FAULT); }
////////////////TANGENT_METHODS//////////////// /////////////////////////////////////////////// /////////////INSIDE_BELONGS_METHODS//////////// public override bool isPointInside(GlPointR2 P) { if (P == null || P.isNullPoint()) { return(false); } GlPointR2 TP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center); return(Math.Pow(TP.X / RealHalfAixis, 2.0) - Math.Pow(TP.Y / AdditionalHalfAixis, 2.0) - 1 > -FAULT); }
public override bool isPointBelongs(GlPointR2 P) { if (P == null || P.isNullPoint()) { return(false); } GlPointR2 RP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Vertex); GlParabola RPB = new GlParabola(this.A, new GlPointR2(0, 0), new GlVectorR2(1, 0)); return(Math.Abs(RP.Y - RPB.A * RP.X * RP.X - RPB.B * RP.X - RPB.C) < FAULT); }
/////////////INTERSECTION_METHODS////////////// /////////////////////////////////////////////// ////////////////TANGENT_METHODS//////////////// public GlLineR2[] getTangentFromPoint(GlPointR2 P) { if (P == null || P.isNullPoint() || this.isPointInside(P)) { return new GlLineR2[] { } } ; GlOval IO = new GlOval(this.RadA, this.RadB, new GlVectorR2(this.RadA, 0.0f), new GlPointR2(0.0f, 0.0f)); GlPointR2 MovedPoint = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY)); if (this.RadA > this.RadB) { IO = new GlOval(this.RadB, this.RadA, this.directVector.getRotatedVector((float)Math.PI / 2), new GlPointR2(0.0f, 0.0f)); MovedPoint.moveTo(MovedPoint.Y, -MovedPoint.X); } float Devider = (float)(Math.Pow(IO.RadA * MovedPoint.Y, 2.0) + Math.Pow(IO.RadB * MovedPoint.X, 2.0)); float fPartRes = (float)Math.Pow(IO.RadA, 3.0) * IO.RadB * MovedPoint.X; float sPartRes = IO.RadA * IO.RadA * MovedPoint.Y * (float)Math.Sqrt(Math.Abs(-Math.Pow(IO.RadA, 4.0) + Math.Pow(IO.RadA * MovedPoint.Y, 2.0) + Math.Pow(IO.RadB * MovedPoint.X, 2.0))); float xI1 = (fPartRes + sPartRes) / Devider; float xI2 = (fPartRes - sPartRes) / Devider; float yI1 = (MovedPoint.X < 0 ? 1 : -1) * IO.RadB * (float)Math.Sqrt(Math.Abs(IO.RadA * IO.RadA - xI1 * xI1)) / IO.RadA; float yI2 = (MovedPoint.X < 0 ? -1 : 1) * IO.RadB * (float)Math.Sqrt(Math.Abs(IO.RadA * IO.RadA - xI2 * xI2)) / IO.RadA; if (Math.Abs(MovedPoint.X) < IO.RadA) { yI1 = (MovedPoint.Y < 0 && yI1 >= 0) ? -Math.Abs(yI1) : ((MovedPoint.Y > 0 && yI1 < 0) ? Math.Abs(yI1) : yI1); yI2 = (MovedPoint.Y < 0 && yI2 >= 0) ? -Math.Abs(yI2) : ((MovedPoint.Y > 0 && yI2 < 0) ? Math.Abs(yI2) : yI2); } if (this.RadA > this.RadB) { float temp = xI1; xI1 = -yI1; yI1 = temp; temp = xI2; xI2 = -yI2; yI2 = temp; } GlPointR2 P1 = new GlPointR2(xI1, yI1).getTranslatedBackPoint(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY)); GlPointR2 P2 = new GlPointR2(xI2, yI2).getTranslatedBackPoint(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY)); return(new GlLineR2[] { new GlLineR2(P1, new GlVectorR2(P1.X - P.X, P1.Y - P.Y)), new GlLineR2(P2, new GlVectorR2(P2.X - P.X, P2.Y - P.Y)) }); }
public GlPointR2 getProjection(GlPointR2 P) { if (P == null || this.PointOfLine.isNullPoint() || P.isNullPoint()) { return(new GlPointR2(null)); } if (this.DirectVector.isNullVector()) { return(this.pointOfLine); } float both = (this.DirectVector.deltaX * (P.X - this.pointOfLine.X) + this.DirectVector.deltaY * (P.Y - this.pointOfLine.Y)) / (float)Math.Pow(this.DirectVector.Length, 2.0); return(new GlPointR2(this.DirectVector.deltaX * both + this.pointOfLine.X, this.DirectVector.deltaY * both + this.pointOfLine.Y)); }
/////////////INTERSECTION_METHODS////////////// /////////////////////////////////////////////// ////////////////TANGENT_METHODS//////////////// public override GlLineR2 getTangentFromBelongs(GlPointR2 P) { if (P == null || P.isNullPoint()) { return(new GlLineR2(new GlPointR2(null), new GlVectorR2(null))); } GlParabola TPB = new GlParabola(this.A, new GlPointR2(0, 0), new GlVectorR2(1, 0)); GlPointR2 TP = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Vertex); float k = 2 * TPB.A * TP.X + TPB.B; GlLineR2 tangent = new GlLineR2(P, new GlVectorR2(1, 0).getRotatedVector((float)Math.Atan(k))); tangent.Rotate(this.SIN, this.COS); return(tangent); }
public override GlLineR2 getTangentFromBelongs(GlPointR2 P) { if (P == null || P.isNullPoint() || !this.isPointBelongs(P) || this.RadA == 0.0f) { return(new GlLineR2(new GlPointR2(null), new GlVectorR2(null))); } GlOval IO = new GlOval(this.RadA, this.RadB, new GlVectorR2(this.RadA, 0.0f), new GlPointR2(0.0f, 0.0f)); GlPointR2 MovedPoint = P.getPointTranslatedToRotatedSystem(this.SIN, this.COS, new GlPointR2(this.CenterX, this.CenterY)); GlLineR2 tangent = new GlLineR2(MovedPoint, new GlVectorR2(-(float)Math.Pow(this.RadA, 2.0) * MovedPoint.Y, (float)Math.Pow(this.RadB, 2.0) * MovedPoint.X)); tangent.Rotate(this.SIN, this.COS); tangent.moveTo(P); return(tangent); }
/////////////INSIDE_BELONGS_METHODS//////////// /////////////////////////////////////////////// ///////////////ADDITIONAL_METHODS////////////// public float getDistance(GlPointR2 P) { if (P == null || this.pointOfLine.isNullPoint() || P.isNullPoint()) { return(float.NaN); } if (GlPointR2.Equals(P, this.pointOfLine)) { return(0); } if (this.DirectVector.isNullVector()) { return(P.getDistance(this.PointOfLine)); } GlVectorR2 directVector = new GlVectorR2(this.DirectVector.deltaX, this.DirectVector.deltaY); return((new GlVectorR2(P.X - this.pointOfLine.X, P.Y - this.pointOfLine.Y) ^ directVector) / (float)directVector.Length); }
public override bool isPointBelongs(GlPointR2 P) { if (P == null || P.isNullPoint()) { return(false); } if (new GlLineSegment(vertexes[this.CountOfPoints - 1], vertexes[0]).isPointBelongs(P)) { return(true); } for (int i = 0; i < this.CountOfPoints - 1; i++) { if (new GlLineSegment(vertexes[i], vertexes[i + 1]).isPointBelongs(P)) { return(true); } } return(false); }
/// <returns>A circle of curvature in a given point of curve</returns> public GlCircle getCurvatureCircle(GlPointR2 belongsPoint) { if (belongsPoint == null || belongsPoint.isNullPoint() || !this.isPointBelongs(belongsPoint)) { return(new GlCircle(float.NaN, new GlPointR2(float.NaN, float.NaN))); } GlPointR2 P = belongsPoint.getPointTranslatedToRotatedSystem(SIN, COS, Center); float sDiff = getSDiff(P.X); if (sDiff == 0) { return(new GlCircle(float.NaN, new GlPointR2(float.NaN, float.NaN))); } float fDiff = getFDiff(P.X); float fDiffPow = (float)Math.Pow(fDiff, 2.0); return(new GlCircle((float)(Math.Pow(1 + fDiffPow, 1.5) / Math.Abs(sDiff)), new GlPointR2(P.X - fDiff * (1 + fDiffPow) / sDiff, P.Y + (P.Y < 0 ? -1 : 1) * (1 + fDiffPow) / sDiff).getTranslatedBackPoint(SIN, COS, Center))); }
////////////////DRAW_METHODS/////////////////// /////////////////////////////////////////////// /////////////INSIDE_BELONGS_METHODS//////////// public override bool isPointBelongs(GlPointR2 P) { return((P == null || P.isNullPoint() || this.isNullLine()) ? false : Math.Abs((P.X - this.pointOfLine.X) * this.DirectVector.deltaY - (P.Y - this.pointOfLine.Y) * this.DirectVector.deltaX) < FAULT); }
/// <summary> /// Checks if given points are equal /// </summary> public bool Equals(GlPointR2 P) { return((P == null || this.isNullPoint() || P.isNullPoint()) ? false : this.X == P.X && this.Y == P.Y); }
/// <summary> /// Checks if given points are equal /// </summary> public static bool Equals(GlPointR2 P1, GlPointR2 P2) { return((P1 == null || P2 == null || P1.isNullPoint() || P2.isNullPoint()) ? false : P1.X == P2.X && P1.Y == P2.Y); }
////////////////DRAW_METHODS/////////////////// /////////////////////////////////////////////// ///////////////ADDITIONAL_METHODS////////////// /// <summary> /// Determines the distance between given points /// </summary> public float getDistance(GlPointR2 P) { return((this == null || P == null || this.isNullPoint() || P.isNullPoint()) ? float.NaN : (float)Math.Sqrt(Math.Pow(this.X - P.X, 2.0) + Math.Pow(this.Y - P.Y, 2.0))); }
////////////////TRANSFORM_METHODS////////////// /////////////////////////////////////////////// ///////////////INTERSECTION_METHODS//////////// /// <summary> /// Determines an anmount of points, created by intersection of a figure and a point /// </summary> /// <returns>An array of intersections</returns> public GlPointR2[] getIntersection(GlPointR2 P) { return((P == null || P.isNullPoint() || !this.isPointBelongs(P)) ? new GlPointR2[] { } : new GlPointR2[] { P }); }