Exemple #1
0
 public void RotateLocal(float angle)
 {
     if (Lines.Count != 0)
     {
         for (int i = 0; i < Lines.Count; i++)
         {
             Lines[i].startPoint = LinePrimatives.RotatePoint(Vector2.Zero, angle, Lines[i].startPoint);
             Lines[i].endPoint   = LinePrimatives.RotatePoint(Vector2.Zero, angle, Lines[i].endPoint);
         }
     }
 }
 public static void DrawRectangle(SpriteBatch spriteBatch, float width, Color color, Rectangle Rec, float Roation, Vector2 Center)
 {
     LineDrawer.DrawLine(spriteBatch, width, color, RotatePoint(Center, Roation, new Vector2((Rec.X), (Rec.Y))), LinePrimatives.RotatePoint(Center, Roation, new Vector2((Rec.X + Rec.Width), (Rec.Y))));
     LineDrawer.DrawLine(spriteBatch, width, color, RotatePoint(Center, Roation, new Vector2((Rec.X + Rec.Width), Rec.Y)), LinePrimatives.RotatePoint(Center, Roation, new Vector2((Rec.X + Rec.Width), (Rec.Y + Rec.Height))));
     LineDrawer.DrawLine(spriteBatch, width, color, RotatePoint(Center, Roation, new Vector2((Rec.X + Rec.Width), (Rec.Y + Rec.Height))), LinePrimatives.RotatePoint(Center, Roation, new Vector2((Rec.X), (Rec.Y + Rec.Height))));
     LineDrawer.DrawLine(spriteBatch, width, color, RotatePoint(Center, Roation, new Vector2((Rec.X), (Rec.Y + Rec.Height))), LinePrimatives.RotatePoint(Center, Roation, new Vector2((Rec.X), (Rec.Y))));
 }
 public static void DrawPoint(SpriteBatch spriteBatch, float width, Color color, Vector2 location)
 {
     LinePrimatives.DrawCircle(spriteBatch, width / 2, color, location, width / 2, (int)width * 2);
 }
Exemple #4
0
 public float Radius(float angle)
 {
     return(LinePrimatives.AngleToEllipseV2(angle + Roation, Axis).Length());
 }
Exemple #5
0
 public void Draw(SpriteBatch spriteBatch)
 {
     LinePrimatives.DrawEllipse(spriteBatch, Width, color, Position, Axis, Roation, Center, Sides);
 }
 public void Draw(SpriteBatch spriteBatch, Vector2 Offset, float Rotation, Vector2 Scale)
 {
     // TO DO: Add in code for Rotation around a Point that is not the Origin
     LineDrawer.DrawLine(spriteBatch, width, color, LinePrimatives.RotatePoint(Vector2.Zero, Rotation, startPoint * Scale) + Offset, LinePrimatives.RotatePoint(Vector2.Zero, Rotation, endPoint * Scale) + Offset);
 }
 public float Angle()
 {
     return(LinePrimatives.V2ToAngle(startPoint, endPoint));
 }
Exemple #8
0
        public Vector2?Intersect(Ellipse other)
        {
            // If the ellipse or line segment are empty, (that is smaller than the percision) forget the work and return no intersections.
            if ((this.Length() <= PERCISION) && (other.Axis.X <= PERCISION) && (other.Axis.Y <= PERCISION))
            {
                return(null);
            }

            // Make sure the axis has non-negative width and height.
            if (other.Axis.X < 0)
            {
                other.Axis.X = -other.Axis.X;
            }
            if (other.Axis.Y < 0)
            {
                other.Axis.Y = -other.Axis.Y;
            }



            // Need to translate the start and end points of the line
            // the need
            Vector2 tstartPoint = startPoint - other.Position;
            Vector2 tendPoint   = endPoint - other.Position;

            float Offsetroation = -other.Roation;

            if (other.Roation != 0)
            {
                tstartPoint = LinePrimatives.RotatePoint(Vector2.Zero, Offsetroation, tstartPoint);
                tendPoint   = LinePrimatives.RotatePoint(Vector2.Zero, Offsetroation, tendPoint);
            }

            Vector2 AxisLocation = Vector2.Zero;

            AxisLocation.X = other.Axis.X;
            AxisLocation.Y = other.Axis.Y;

            if (AxisLocation.X < 0)
            {
                AxisLocation.X = -AxisLocation.X;
            }
            if (AxisLocation.Y < 0)
            {
                AxisLocation.Y = -AxisLocation.Y;
            }
            // Calculate the quadratic parameters.

            float A = (tendPoint.X - tstartPoint.X) * (tendPoint.X - tstartPoint.X) / AxisLocation.X / AxisLocation.X +
                      (tendPoint.Y - tstartPoint.Y) * (tendPoint.Y - tstartPoint.Y) / AxisLocation.Y / AxisLocation.Y;
            float B = 2 * tstartPoint.X * (tendPoint.X - tstartPoint.X) / AxisLocation.X / AxisLocation.X +
                      2 * tstartPoint.Y * (tendPoint.Y - tstartPoint.Y) / AxisLocation.Y / AxisLocation.Y;
            float C = tstartPoint.X * tstartPoint.X / AxisLocation.X / AxisLocation.X + tstartPoint.Y * tstartPoint.Y / AxisLocation.Y / AxisLocation.Y - 1;


            // Make a list of t values.
            List <float> t_values = new List <float>();

            // Calculate the discriminant.
            float discriminant = B * B - 4 * A * C;

            if (discriminant == 0)
            {
                // One real solution.
                t_values.Add(-B / 2 / A);
            }
            else if (discriminant > 0)
            {
                // Two real solutions.
                t_values.Add((float)((-B + Math.Sqrt(discriminant)) / 2 / A));
                t_values.Add((float)((-B - Math.Sqrt(discriminant)) / 2 / A));
            }

            //Console.WriteLine(t_values.Count);
            // Convert the t values into points.
            List <Vector2?> points = new List <Vector2?>();

            foreach (float t in t_values)
            {
                // If the points are on the segment add them to the list.
                if (((t >= 0f) && (t <= 1f)))
                {
                    float   x    = tstartPoint.X + (tendPoint.X - tstartPoint.X) * t;
                    float   y    = tstartPoint.Y + (tendPoint.Y - tstartPoint.Y) * t;
                    Vector2 tVec = new Vector2(x, y);
                    if (other.Roation != 0)
                    {
                        tVec = LinePrimatives.RotatePoint(Vector2.Zero, -Offsetroation, tVec);
                    }
                    tVec += other.Position;
                    points.Add(tVec);
                }
            }


            // Return the closest point to the line start point if an intersection exists
            if (points.Count == 0)
            {
                return(null);
            }
            if (points.Count == 1)
            {
                return(points[0]);
            }


            if (Vector2.Distance(startPoint, points[0].Value) <= Vector2.Distance(startPoint, points[1].Value))
            {
                return(points[0]);
            }
            else
            {
                return(points[1]);
            }
        }