2 using System.Collections.Generic;
16 private struct PointAndDistanceToOtherPoint
25 public Point Point {
get {
return point; } }
30 private double distance;
34 public double Distance {
get {
return distance; } }
42 internal PointAndDistanceToOtherPoint(Point point, Point otherPoint)
45 distance = (otherPoint - point).Length;
52 private Point firstControlLocation;
56 public Point FirstControlLocation
58 get {
return firstControlLocation; }
59 set { firstControlLocation = value; }
65 private Point secondControlLocation;
69 public Point SecondControlLocation
71 get {
return secondControlLocation; }
72 set { SecondControlLocation = value; }
82 public BezierLane(Point startLocation, Point firstControlLocation, Point secondControlLocation,
84 : base(startLocation, endLocation)
86 this.firstControlLocation = firstControlLocation;
87 this.secondControlLocation = secondControlLocation;
95 internal override IEnumerable<Point> LanePoints(
double lanePointsMaxDistance)
99 yield
return lastPoint = startNode.Location;
102 double currentT = 0.0;
103 double distanceDivided10 = lanePointsMaxDistance / 10.0;
104 while (currentT < 1.0)
107 double tBase = currentT;
109 double tRange = 1.0 - currentT;
111 double tAddend = tRange / 2.0;
114 while ((lastPoint - ComputePoint(tBase + tAddend)).Length > distanceDivided10)
119 PointAndDistanceToOtherPoint previousPointAndDistanceToOtherPoint =
120 new PointAndDistanceToOtherPoint(lastPoint, lastPoint);
121 PointAndDistanceToOtherPoint currentPointAndDistanceToOtherPoint =
122 new PointAndDistanceToOtherPoint(lastPoint, lastPoint);
124 while (currentPointAndDistanceToOtherPoint.Distance < lanePointsMaxDistance && currentT < 1.0)
127 previousPointAndDistanceToOtherPoint = currentPointAndDistanceToOtherPoint;
128 currentPointAndDistanceToOtherPoint =
129 new PointAndDistanceToOtherPoint(ComputePoint(currentT), lastPoint);
136 if (previousPointAndDistanceToOtherPoint.Distance < currentPointAndDistanceToOtherPoint.Distance)
139 lastPoint = previousPointAndDistanceToOtherPoint.Point;
143 lastPoint = currentPointAndDistanceToOtherPoint.Point;
145 yield
return lastPoint;
148 yield
return endNode.Location;
156 private Point ComputePoint(
double t)
158 Point p =
new Point();
160 p.X = u * u * u * startNode.Location.X +
161 3 * u * u * t * firstControlLocation.X +
162 3 * u * t * t * secondControlLocation.X +
163 t * t * t * endNode.Location.X;
164 p.Y = u * u * u * startNode.Location.Y +
165 3 * u * u * t * firstControlLocation.Y +
166 3 * u * t * t * secondControlLocation.Y +
167 t * t * t * endNode.Location.Y;
Represents single bezier lane.
BezierLane(Point startLocation, Point firstControlLocation, Point secondControlLocation, Point endLocation)
Constructor for bezier lane.