Esempio n. 1
0
 public PointD Offset(PointD point)
 {
     return new PointD(this.X + point.X, this.Y + point.Y);
 }
Esempio n. 2
0
 public Puck()
 {
     Velocity = new Velocity();
     Location = new PointD(0, 0);
 }
Esempio n. 3
0
        public static CollisionData GetClosestCollisionData(Puck p, double offset, PointD ghost_puck_location, Puck c, Table table)
        {
            List<Line> collision_lines = new List<Line>();
            collision_lines.AddRange(table.Walls);

            for (int j = 0; j < table.Arcs.Count; ++j)
            {
                PointD[] center_point_collisions = p.Path.IntersectionWith(table.Arcs[j]);
                if (center_point_collisions != null)
                {
                    for (int i = 0; i < center_point_collisions.Length; ++i)
                    {
                        if (center_point_collisions[i] != null)
                        {
                            Line line_thru_center = new Line(table.Arcs[j].Point, (double?)((center_point_collisions[i].Y - table.Arcs[j].Point.Y) / (center_point_collisions[i].X - table.Arcs[j].Point.X)));
                            Line projection_line = line_thru_center.Perpendicular(center_point_collisions[i]);
                            collision_lines.Add(projection_line);
                        }
                    }
                }
            }

            List<CollisionData> potential_collision_points = new List<CollisionData>();
            for (int j = 0; j < collision_lines.Count; ++j) {
                PointD center_point_collision = p.Path.IntersectionWith(collision_lines[j]);
                if (center_point_collision != null) {
                    double sc = p.Location.DistanceTo(center_point_collision);
                    double fc = ghost_puck_location.DistanceTo(center_point_collision);
                    if (!(fc > sc && fc > offset)) {
                        Line projection_line = ProjectionLine(p, collision_lines[j]);
                        PointD projection_collision = p.Path.IntersectionWith(projection_line);
                        if (offset > projection_collision.DistanceTo(p.Location)) {
                            potential_collision_points.Add(new CollisionData(projection_collision, projection_line));
                        }
                    }
                }
            }

            //TODO: check for collision with computer puck, add result to potential collision points right here
            //for (int j = 0; j < table.Arcs.Count; ++j)
            //{
            //    Arc projection_arc = p.Location.DistanceTo(table.Arcs[j].Point) < table.Arcs[j].Radius
            //        ? new Arc(table.Arcs[j].Point, table.Arcs[j].Radius - p.Radius)
            //        : new Arc(table.Arcs[j].Point, table.Arcs[j].Radius + p.Radius);
            //
            //    PointD[] center_point_collisions = p.Path.IntersectionWith(table.Arcs[j]);
            //    if (center_point_collisions != null)
            //    {
            //        for (int i = 0; i < center_point_collisions.Length; ++i)
            //        {
            //            if (center_point_collisions[i] != null)
            //            {
            //                double sc = p.Location.DistanceTo(center_point_collisions[i]);
            //                double fc = ghost_puck_location.DistanceTo(center_point_collisions[i]);
            //                if (!(fc > sc && fc > offset))
            //                {
            //                    PointD[] projection_collisions = p.Path.IntersectionWith(projection_arc);
            //                    foreach (var projection_collision in projection_collisions)
            //                    {
            //                        Line line_thru_center = new Line(table.Arcs[j].Point, (double?)((projection_collision.Y - projection_arc.Point.Y) / (projection_collision.X - projection_arc.Point.X)));
            //                        Line projection_line = line_thru_center.Perpendicular(projection_collision);
            //                        if (offset > projection_collision.DistanceTo(p.Location)) {
            //                            potential_collision_points.Add(new CollisionData(projection_collision, projection_line));
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}

            potential_collision_points = potential_collision_points.OrderBy(z => z.collision_point.DistanceTo(p.Location)).ToList();
            return potential_collision_points.Count > 0 ? potential_collision_points[0] : null;
        }
Esempio n. 4
0
 public double DistanceTo(PointD point)
 {
     return Math.Sqrt(Math.Pow(point.X - this.X, 2) + Math.Pow(point.Y - this.Y, 2));
 }
Esempio n. 5
0
 public CollisionData(PointD cp, Line pl)
 {
     collision_point = cp; projection_line = pl;
 }
Esempio n. 6
0
 public Line Parallel(PointD point)
 {
     return new Line(point, this.Slope);
 }
Esempio n. 7
0
 public Line(PointD point, Angle angle)
 {
     Point = point; Angle = angle;
 }
Esempio n. 8
0
 public Line(PointD point, double? slope)
 {
     Point = point; Slope = slope;
 }
Esempio n. 9
0
 public Line Perpendicular(PointD point)
 {
     return new Line(point, this.Slope != null ? -1 / this.Slope : 0);
 }