|
@@ -11,30 +11,48 @@ namespace SketchAssistantWPF
|
|
|
{
|
|
|
static int constantA= 10;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
InternalLine currentLine;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
List<Point> currentPoints;
|
|
|
|
|
|
- Point lastCursorPosition;
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
int index;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public void setCurrentLine(InternalLine newCurrentLine)
|
|
|
{
|
|
|
currentLine = newCurrentLine;
|
|
|
currentPoints = currentLine.GetPoints();
|
|
|
- lastCursorPosition = currentPoints.ElementAt(0);
|
|
|
+
|
|
|
index = 1;
|
|
|
}
|
|
|
|
|
|
- public int GenerateTrajectory(Point cursorPosition)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public double GenerateTrajectory(Point cursorPosition)
|
|
|
{
|
|
|
|
|
|
|
|
|
- while (index < (currentPoints.Count - 1) && SectionDividingLinePassed(lastCursorPosition, cursorPosition, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index), currentPoints.ElementAt(index + 1)))
|
|
|
+ while (index < (currentPoints.Count - 1) && SectionDividingLinePassed(cursorPosition, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index), currentPoints.ElementAt(index + 1)))
|
|
|
{
|
|
|
index++;
|
|
|
}
|
|
|
- lastCursorPosition = cursorPosition;
|
|
|
+
|
|
|
|
|
|
|
|
|
Point orthogonalProjection = ComputeOrthogonalProjection(cursorPosition, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index));
|
|
@@ -44,10 +62,10 @@ namespace SketchAssistantWPF
|
|
|
List<Tuple<Point, Point>> strikeZones = new List<Tuple<Point, Point>>();
|
|
|
|
|
|
|
|
|
- Point auxiliaryPoint = null;
|
|
|
+ Point auxiliaryPoint = new Point(-1, -1);
|
|
|
if (ComputeDistance(orthogonalProjection, currentPoints.ElementAt(index)) <= constantA)
|
|
|
{
|
|
|
- auxiliaryPoint = moveAlongLine(orthogonalProjection, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index), constantA);
|
|
|
+ auxiliaryPoint = MoveAlongLine(orthogonalProjection, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index), constantA);
|
|
|
strikeZones.Add(computeStrikeZone(auxiliaryPoint, orthogonalProjection, cursorPosition));
|
|
|
targetIndex--;
|
|
|
}
|
|
@@ -59,13 +77,13 @@ namespace SketchAssistantWPF
|
|
|
targetIndex++;
|
|
|
}
|
|
|
|
|
|
- Point furthestCrossingPoint = null;
|
|
|
+ Point furthestCrossingPoint = new Point(-1, -1); ;
|
|
|
if (targetIndex < index)
|
|
|
{
|
|
|
furthestCrossingPoint = ComputeFurthestCrossingPoint(cursorPosition, strikeZones, auxiliaryPoint, currentPoints.ElementAt(targetIndex + 1));
|
|
|
|
|
|
|
|
|
- if (furthestCrossingPoint != null)
|
|
|
+ if (furthestCrossingPoint.X != -1)
|
|
|
{
|
|
|
Debug_DrawStrikeZones(strikeZones);
|
|
|
Debug_DrawTrajectoryVector(cursorPosition, furthestCrossingPoint);
|
|
@@ -87,7 +105,7 @@ namespace SketchAssistantWPF
|
|
|
furthestCrossingPoint = ComputeFurthestCrossingPoint(cursorPosition, strikeZones, currentPoints.ElementAt(targetIndex), currentPoints.ElementAt(targetIndex + 1));
|
|
|
}
|
|
|
|
|
|
- if (furthestCrossingPoint != null)
|
|
|
+ if (furthestCrossingPoint.X != -1)
|
|
|
{
|
|
|
Debug_DrawStrikeZones(strikeZones);
|
|
|
Debug_DrawTrajectoryVector(cursorPosition, furthestCrossingPoint);
|
|
@@ -128,9 +146,11 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
|
|
|
- private int computeOrientationOfVector(Point vectorStartPoint, Point vectorEndPoint)
|
|
|
+ private double computeOrientationOfVector(Point vectorStartPoint, Point vectorEndPoint)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ double x = vectorEndPoint.X - vectorStartPoint.X;
|
|
|
+ double y = vectorEndPoint.Y - vectorStartPoint.Y;
|
|
|
+ return Math.Atan( y / x );
|
|
|
}
|
|
|
|
|
|
|
|
@@ -178,7 +198,7 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
|
|
|
- private Point moveAlongLine(Point pointToBeMoved, Point lineStartPoint, Point lineEndPoint, int distance)
|
|
|
+ private Point MoveAlongLine(Point pointToBeMoved, Point lineStartPoint, Point lineEndPoint, double distance)
|
|
|
{
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
@@ -189,19 +209,37 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
|
|
|
- private int ComputeDistance(Point point1, Point point2)
|
|
|
+ private double ComputeDistance(Point point1, Point point2)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ return Math.Sqrt( (double) ( Math.Pow((point2.X - point1.X), 2) + Math.Pow((point2.Y - point1.Y), 2) ) );
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private Point ComputeOrthogonalProjection(Point cursorPosition, Point lastPoint, Point currentPoint)
|
|
|
{
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
|
- private bool SectionDividingLinePassed(Point lastCursorPosition, Point cursorPosition, Point lastPoint, Point currentPoint, Point nextPoint)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private bool SectionDividingLinePassed(Point cursorPosition, Point lastPoint, Point currentPoint, Point nextPoint)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+
|
|
|
+ Point auxiliaryPoint = MoveAlongLine(currentPoint, currentPoint, lastPoint, ComputeDistance(currentPoint, nextPoint));
|
|
|
+
|
|
|
+ return ComputeDistance(cursorPosition, nextPoint) <= ComputeDistance(cursorPosition, auxiliaryPoint);
|
|
|
}
|
|
|
}
|
|
|
}
|