/////////////////////////////////////////////// //////////////////PROPERTIES/////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// ////////////////////METHODS//////////////////// /////////////////////////////////////////////// //////////////TRANSFORM_METHODS//////////////// public override void moveTo(float x, float y) { if (OnMoveStart != null) { if (!OnMoveStart.Invoke(this, this.polyCenter.X, this.polyCenter.Y)) { return; } } if (OnMoving != null) { OnMoving.Invoke(this, this.polyCenter.X, this.polyCenter.Y); } GlVectorR2 delta = new GlVectorR2(x - polyCenter.X, y - polyCenter.Y); for (int i = 0; i < vertexes.Length; i++) { vertexes[i] = delta.fromPointToPoint(vertexes[i]); } GlPointR2 OP = new GlPointR2(this.polyCenter); this.polyCenter = new GlPointR2(x, y); if (OnMoved != null) { OnMoved.Invoke(this, OP.X, OP.Y); } }
public override void Rotate(float SIN, float COS) { if (OnRotateStart != null) { if (!OnRotateStart.Invoke(this, SIN, COS)) { return; } } if (OnRotating != null) { OnRotating.Invoke(this, SIN, COS); } for (int i = 0; i < vertexes.Length; i++) { vertexes[i] = new GlVectorR2(vertexes[i].X - polyCenter.X, vertexes[i].Y - polyCenter.Y).getRotatedVector(-SIN, COS).fromPointToPoint(polyCenter); } if (OnRotated != null) { OnRotated.Invoke(this, SIN, COS); } }
/////////////////////////////////////////////// //////////////////PROPERTIES/////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// ////////////////////METHODS//////////////////// /////////////////////////////////////////////// //////////////TRANSFORM_METHODS//////////////// public override void moveTo(float x, float y) { float oldX = systemCenter.X, oldY = systemCenter.Y; if (OnMoveStart != null) { if (!OnMoveStart.Invoke(this, oldX, oldY)) { return; } } if (OnMoving != null) { OnMoving.Invoke(this, oldX, oldY); } GlVectorR2 moveVector = new GlVectorR2(x - this.systemCenter.X, y - this.systemCenter.Y); this.systemCenter = new GlPointR2(x, y); foreach (GlFigure F in this.figuresAmount) { GlPointR2 newCenter = moveVector.fromPointToPoint(F.Center); F.moveTo(newCenter.X, newCenter.Y); } if (OnMoved != null) { OnMoving.Invoke(this, oldX, oldY); } }
public override void Rotate(float SIN, float COS) { float oldX = this.Center.X; float oldY = this.Center.Y; if (OnRotateStart != null) { if (!OnRotateStart.Invoke(this, SIN, COS)) { return; } } if (OnRotating != null) { OnRotating.Invoke(this, SIN, COS); } this.directVector = this.directVector.getRotatedVector(-SIN, COS); updatePointsPosition(); if (OnRotated != null) { OnRotated.Invoke(this, SIN, COS); } }
/////////////////////////////////////////////// ////////////////////FIELDS///////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// public GlHyperbola(float realHalfAxis, float additionalHalfAxis, GlVectorR2 xAxisDirection, GlPointR2 systemCenter) { this.curvePoints = new GlPointR2[179]; if (xAxisDirection == null || systemCenter == null) { directVector = new GlVectorR2(0, 0); systemCenter = new GlPointR2(float.NaN, float.NaN); Ra = 0; Rb = 0; return; } this.directVector = xAxisDirection; this.systemCenter = systemCenter; this.Ra = realHalfAxis; this.Rb = additionalHalfAxis; if (directVector.isNullVector() || systemCenter.isNullPoint()) { return; } updatePointsPosition(); }
/////////////////////////////////////////////// ////////////////////FIELDS///////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// /// <param name="R1">size of X half-axis</param> /// <param name="R2">size of Y half-axis</param> /// <param name="VectorR1">Vector of x-axis positive direction</param> /// <param name="OvalCenter">Point of the center of the oval</param> public GlOval(float R1, float R2, GlVectorR2 VectorR1, GlPointR2 OvalCenter) { this.curvePoints = new GlPointR2[360]; if (VectorR1 == null || OvalCenter == null) { directVector = new GlVectorR2(0, 0); systemCenter = new GlPointR2(float.NaN, float.NaN); Ra = 0; Rb = 0; return; } this.systemCenter = new GlPointR2(OvalCenter); this.Ra = R1; this.Rb = R2; this.directVector = VectorR1; if (VectorR1.isNullVector()) { return; } this.Length = (int)Math.Ceiling(Math.PI * Math.Sqrt(2 * (R1 * R1 + R2 * R2))); updatePointsPosition(); }
/// <returns>If the line intersects the oval</returns> public bool isIntersects(GlLineR2 L) { if (L == null || L.isNullLine()) { return(false); } GlVectorR2 LV = L.DirectVector.getRotatedVector(this.SIN, this.COS); return(Math.Pow(this.RadA * LV.deltaY, 2.0) + Math.Pow(this.RadB * LV.deltaX, 2.0) != 0); }
/////////////////////////////////////////////// ////////////////////FIELDS///////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// public GlLineR2(GlPointR2 belongsPoint, GlVectorR2 directVector) { if (belongsPoint == null || directVector == null) { this.directVector = new GlVectorR2(0, 0); pointOfLine = new GlPointR2(float.NaN, float.NaN); return; } this.pointOfLine = belongsPoint; this.directVector = directVector; }
//////////////TRANSFORM_METHODS//////////////// /////////////////////////////////////////////// /////////////INTERSECTION_METHODS////////////// public override GlPointR2[] getIntersection(GlLineR2 L) { GlVectorR2 translatedVector = new GlVectorR2(L.DirectVector).getRotatedVector(this.SIN, this.COS); GlPointR2 FP = L.PointOfLine.getPointTranslatedToRotatedSystem(this.SIN, this.COS, this.Center); GlPointR2 SP = translatedVector.fromPointToPoint(FP); float fPartRes = (float)Math.Pow(AdditionalHalfAixis * (FP.X - SP.X), 2.0); float sPartRes = (float)Math.Pow(RealHalfAixis * (FP.Y - SP.Y), 2.0); float tPartRes = FP.X * SP.Y - SP.X * FP.Y; float sqrtPart = RealHalfAixis * AdditionalHalfAixis * (FP.X - SP.X) * (float)Math.Sqrt(fPartRes - sPartRes + Math.Pow(tPartRes, 2.0)); float x1 = (-(float)Math.Pow(RealHalfAixis, 2.0) * (FP.Y - SP.Y) * tPartRes + sqrtPart) / (sPartRes - fPartRes); float x2 = (-(float)Math.Pow(RealHalfAixis, 2.0) * (FP.Y - SP.Y) * tPartRes - sqrtPart) / (sPartRes - fPartRes); float y1 = AdditionalHalfAixis * (float)Math.Sqrt(x1 * x1 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis; float y2 = -AdditionalHalfAixis * (float)Math.Sqrt(x2 * x2 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis; float y3 = -AdditionalHalfAixis * (float)Math.Sqrt(x1 * x1 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis; float y4 = AdditionalHalfAixis * (float)Math.Sqrt(x2 * x2 - Math.Pow(RealHalfAixis, 2.0)) / RealHalfAixis; GlPointR2[] RP = { new GlPointR2(x1, y1).getTranslatedBackPoint(this.SIN, this.COS, this.Center), new GlPointR2(x2, y2).getTranslatedBackPoint(this.SIN, this.COS, this.Center), new GlPointR2(x1, y3).getTranslatedBackPoint(this.SIN, this.COS, this.Center), new GlPointR2(x2, y4).getTranslatedBackPoint(this.SIN, this.COS, this.Center) }; List <GlPointR2> res = new List <GlPointR2>(); for (int i = 0; i < RP.Length; i++) { bool a = this.isPointBelongs(RP[i]); bool b = L.isPointBelongs(RP[i]); if (a && b) { res.Add(RP[i]); } } return(res.ToArray()); }
/////////////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 void Rotate(float SIN, float COS) { if (OnRotateStart != null) { if (!OnRotateStart.Invoke(this, SIN, COS)) { return; } } if (OnRotating != null) { OnRotating.Invoke(this, SIN, COS); } this.directVector = this.DirectVector.getRotatedVector(-SIN, COS); if (OnRotated != null) { OnRotated.Invoke(this, SIN, COS); } }
/////////////////////////////////////////////// ////////////////////FIELDS///////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// public GlPolygon(GlPointR2 Center, params GlPointR2[] POLY) { S = 0; if (POLY == null || Center == null) { polyCenter = new GlPointR2(float.NaN, float.NaN); vertexes = new GlPointR2[0]; return; } if (POLY.Length > 3) { GlPointR2 P = new GlPointR2((POLY[0].X + POLY[POLY.Length / 2].X) / 2, (POLY[0].Y + POLY[POLY.Length / 2].Y) / 2); for (int i = 0; i < POLY.Length - 1; i++) { S += new GlTriangle(P, POLY[i], POLY[i + 1]).S; } S += new GlTriangle(P, POLY[POLY.Length - 1], POLY[0]).S; } this.polyCenter = Center; this.vertexes = new GlPointR2[POLY.Length]; Array.Copy(POLY, this.vertexes, this.vertexes.Length); if (this.vertexes.Length == 0) { return; } for (int i = 0; i < this.vertexes.Length - 1; i++) { P += new GlVectorR2(this.vertexes[i + 1].X - this.vertexes[i].X, this.vertexes[i + 1].Y - this.vertexes[i].Y).Length; } P += new GlVectorR2(this.vertexes[0].X - this.vertexes[this.vertexes.Length - 1].X, this.vertexes[0].Y - this.vertexes[this.vertexes.Length - 1].Y).Length; }
/////////////////////////////////////////////// ////////////////////FIELDS///////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// public GlParabola(float aCoeff, GlPointR2 Vertex, GlVectorR2 directVector) { this.curvePoints = new GlPointR2[360]; if (Vertex == null || directVector == null) { this.directVector = new GlVectorR2(0, 0); systemCenter = new GlPointR2(float.NaN, float.NaN); a = 0; return; } this.a = Math.Abs(aCoeff); this.systemCenter = Vertex; this.directVector = (aCoeff < 0 && !directVector.isNullVector()) ? directVector.getReversedVector() : directVector; if (isNullParabola()) { return; } updatePointsPosition(); }
/////////////////////////////////////////////// ////////////////////FIELDS///////////////////// /////////////////////////////////////////////// /*********************************************/ /////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// public GlRectangle(GlPointR2 PLT, float width, float height, GlVectorR2 directVector) : base((PLT == null || directVector == null)? new GlPointR2(float.NaN, float.NaN) : new GlPointR2(PLT.X + (height * directVector.deltaY + width * directVector.deltaX) / (2 * directVector.Length), PLT.Y + (width * directVector.deltaY - height * directVector.deltaX) / (2 * directVector.Length)), (PLT == null || directVector == null)? new GlPointR2[] { new GlPointR2(float.NaN, float.NaN), new GlPointR2(float.NaN, float.NaN), new GlPointR2(float.NaN, float.NaN), new GlPointR2(float.NaN, float.NaN) } : new GlPointR2[] { PLT, new GlPointR2(PLT.X + width * directVector.deltaX / directVector.Length, PLT.Y + width * directVector.deltaY / directVector.Length), new GlLineR2(new GlPointR2(PLT.X + height * directVector.deltaY / directVector.Length, PLT.Y - height * directVector.deltaX / directVector.Length), directVector) .getIntersection(new GlLineR2(new GlPointR2(PLT.X + width * directVector.deltaX / directVector.Length, PLT.Y + width * directVector.deltaY / directVector.Length), directVector.getRotatedVector((float)Math.PI / 2)))[0], new GlPointR2(PLT.X + height * directVector.deltaY / directVector.Length, PLT.Y - height * directVector.deltaX / directVector.Length) } ) { if (PLT == null || directVector == null) { this.directVector = new GlVectorR2(0, 0); this.leftTopPoint = new GlPointR2(float.NaN, float.NaN); this.Width = 0; this.Height = 0; this.S = 0; this.P = 0; } this.directVector = directVector; this.Width = width; this.Height = height; this.leftTopPoint = PLT; this.S = width * height; }
public GlRectangle(GlPointR2 PLT, float width, float height, GlVectorR2 directVector) { }
public GlOval(float R1, float R2, GlVectorR2 directVector, GlPointR2 OvalCenter) { }
/////////////////////////////////////////////// /////////////////CONSTRUCTORS////////////////// /////////////////////////////////////////////// public GlSqaure(GlPointR2 PLT, float sideLength, GlVectorR2 directVector) : base(PLT, sideLength, sideLength, directVector) { }
public GlHyperbola(float RealHalfAxis, float AddHalfAxis, GlVectorR2 directVector, GlPointR2 HypCenter) { }
//////////////TRANSFORM_METHODS//////////////// /////////////////////////////////////////////// /////////////INTERSECTION_METHODS////////////// public override GlPointR2[] getIntersection(GlLineR2 L) { if (L == null || L.pointOfLine.isNullPoint()) { return new GlPointR2[] { } } ; if (GlPointR2.Equals(this.pointOfLine, L.pointOfLine))//already have a result { return new GlPointR2[] { new GlPointR2(L.pointOfLine) } } ; bool isL1Point = this.DirectVector.isNullVector(); bool isL2Point = L.DirectVector.isNullVector(); if (isL1Point && isL2Point)//same points were catched in previous step { return new GlPointR2[] { } } ; if (this.DirectVector.isNullVector() && L.isPointBelongs(this.pointOfLine))//line and a point { return new GlPointR2[] { new GlPointR2(this.pointOfLine) } } ; if (L.DirectVector.isNullVector() && this.isPointBelongs(L.pointOfLine))//line and a point { return new GlPointR2[] { new GlPointR2(L.pointOfLine) } } ; if (GlLineR2.Equals(this, L))//lines are identical { return new GlPointR2[] { new GlPointR2(this.pointOfLine), new GlPointR2(L.PointOfLine) } } ; if (GlVectorR2.isParallel(this.DirectVector, L.DirectVector))//lines are parallel { return new GlPointR2[] { } } ; if (L.DirectVector.deltaX == 0)//L2 is parallel to Y axis { return new GlPointR2[] { new GlPointR2(L.pointOfLine.X, this.DirectVector.deltaY * (L.pointOfLine.X - this.pointOfLine.X) / this.DirectVector.deltaX + this.pointOfLine.Y) } } ; if (this.DirectVector.deltaY == 0)//L1 is parallel to X axis { return new GlPointR2[] { new GlPointR2(L.DirectVector.deltaX * (this.pointOfLine.Y - L.pointOfLine.Y) / L.DirectVector.deltaY + L.pointOfLine.X, this.pointOfLine.Y) } } ; float v2RatYX = L.DirectVector.deltaY / L.DirectVector.deltaX; float v1RatXY = this.DirectVector.deltaX / this.DirectVector.deltaY; float yInter = (v1RatXY * v2RatYX * this.pointOfLine.Y - v2RatYX * this.pointOfLine.X + v2RatYX * L.pointOfLine.X - L.pointOfLine.Y) / (v1RatXY * v2RatYX - 1); float xInter = v1RatXY * (yInter - this.pointOfLine.Y) + this.pointOfLine.X; return(new GlPointR2[] { new GlPointR2(xInter, yInter) });//common situation }
public GlParabola(float aCoeff, GlPointR2 vertex, GlVectorR2 directVector) { }
public GlSquare(GlPointR2 PLT, int side, GlVectorR2 directVector) { }
public GlLineR2(GlPointR2 belongsPoint, GlVectorR2 directVector) { }
public static bool Equals(GlLineR2 L1, GlLineR2 L2) { return((L1 == null || L2 == null || L1.isNullLine() || L2.isNullLine()) ? false : GlVectorR2.isParallel(L1.DirectVector, L2.DirectVector) && GlVectorR2.isParallel(L1.DirectVector, new GlVectorR2(L2.pointOfLine.X - L1.pointOfLine.X, L2.pointOfLine.Y - L1.pointOfLine.Y))); }