|
@@ -9,7 +9,8 @@ namespace SketchAssistantWPF
|
|
|
{
|
|
|
class TrajectoryGenerator
|
|
|
{
|
|
|
- static int constantA= 10;
|
|
|
+ static readonly int CONSTANT_A = 10;
|
|
|
+ static readonly double DEADZONE = 3;
|
|
|
|
|
|
|
|
|
|
|
@@ -63,9 +64,9 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
Point auxiliaryPoint = new Point(-1, -1);
|
|
|
- if (ComputeDistance(orthogonalProjection, currentPoints.ElementAt(index)) <= constantA)
|
|
|
+ if (ComputeDistance(orthogonalProjection, currentPoints.ElementAt(index)) <= CONSTANT_A)
|
|
|
{
|
|
|
- auxiliaryPoint = MoveAlongLine(orthogonalProjection, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index), constantA);
|
|
|
+ auxiliaryPoint = MoveAlongLine(orthogonalProjection, currentPoints.ElementAt(index - 1), currentPoints.ElementAt(index), CONSTANT_A);
|
|
|
strikeZones.Add(computeStrikeZone(auxiliaryPoint, orthogonalProjection, cursorPosition));
|
|
|
targetIndex--;
|
|
|
}
|
|
@@ -80,7 +81,7 @@ namespace SketchAssistantWPF
|
|
|
Point furthestCrossingPoint = new Point(-1, -1); ;
|
|
|
if (targetIndex < index)
|
|
|
{
|
|
|
- furthestCrossingPoint = ComputeFurthestCrossingPoint(cursorPosition, strikeZones, auxiliaryPoint, currentPoints.ElementAt(targetIndex + 1));
|
|
|
+ furthestCrossingPoint = ComputeFurthestCrossingPoint(cursorPosition, orthogonalProjection, strikeZones, auxiliaryPoint, currentPoints.ElementAt(targetIndex + 1));
|
|
|
|
|
|
|
|
|
if (furthestCrossingPoint.X != -1)
|
|
@@ -102,7 +103,7 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
if (targetIndex < (currentPoints.Count - 1))
|
|
|
{
|
|
|
- furthestCrossingPoint = ComputeFurthestCrossingPoint(cursorPosition, strikeZones, currentPoints.ElementAt(targetIndex), currentPoints.ElementAt(targetIndex + 1));
|
|
|
+ furthestCrossingPoint = ComputeFurthestCrossingPoint(cursorPosition, orthogonalProjection, strikeZones, currentPoints.ElementAt(targetIndex), currentPoints.ElementAt(targetIndex + 1));
|
|
|
}
|
|
|
|
|
|
if (furthestCrossingPoint.X != -1)
|
|
@@ -157,11 +158,34 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- private Point ComputeFurthestCrossingPoint(Point cursorPosition, List<Tuple<Point, Point>> strikeZones, Point lineSegmentStartPoint, Point lineSegmentEndPoint)
|
|
|
+ private Point ComputeFurthestCrossingPoint(Point cursorPosition, Point orthogonalProjection, List<Tuple<Point, Point>> strikeZones, Point lineSegmentStartPoint, Point lineSegmentEndPoint)
|
|
|
+ {
|
|
|
+ Tuple<Point, Point> bsf= new Tuple<Point, Point>(new Point(-1, -1), new Point(-1, -1));
|
|
|
+ Double bsfAngle = 180;
|
|
|
+ for (int j = 0; j < strikeZones.Count; j++)
|
|
|
+ {
|
|
|
+ double currentAngle = ComputeAngle(orthogonalProjection, cursorPosition, strikeZones.ElementAt(j).Item2);
|
|
|
+ if (currentAngle < bsfAngle)
|
|
|
+ {
|
|
|
+ bsfAngle = currentAngle;
|
|
|
+ bsf = strikeZones.ElementAt(j);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Point furthestCrossingPoint = ComputeCrossingPoint(cursorPosition, bsf.Item2, lineSegmentStartPoint, lineSegmentEndPoint);
|
|
|
+ return furthestCrossingPoint;
|
|
|
+ }
|
|
|
+
|
|
|
+ private double ComputeAngle(Point point1, Point centerPoint, Point point2)
|
|
|
+ {
|
|
|
+ return (Math.Abs(computeOrientationOfVector(centerPoint, point1) - computeOrientationOfVector(centerPoint, point2)) % 180);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Point ComputeCrossingPoint(Point line1Point1, Point lne1Point2, Point line2Point1, Point line2Point2)
|
|
|
{
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
@@ -171,11 +195,25 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- private bool allStrikeZonesPassed(List<Tuple<Point, Point>> strikeZones, Point cursorPosition, Point targetIndex)
|
|
|
+ private bool allStrikeZonesPassed(List<Tuple<Point, Point>> strikeZones, Point cursorPosition, Point targetPoint)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ foreach (Tuple<Point, Point> s in strikeZones )
|
|
|
+ {
|
|
|
+ if (!SectionsCrossing(cursorPosition, targetPoint, s.Item1, s.Item2)) return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool SectionsCrossing(Point section1StartingPoint, Point section1EndingPoint, Point section2StartingPoint, Point section2EndingPoint)
|
|
|
+ {
|
|
|
+ Point crossingPoint = ComputeCrossingPoint(section1StartingPoint, section1EndingPoint, section2StartingPoint, section2EndingPoint);
|
|
|
+ if (BeyondSection(crossingPoint, section1StartingPoint, section1EndingPoint)) return false;
|
|
|
+ if (BeyondSection(crossingPoint, section1EndingPoint, section1StartingPoint)) return false;
|
|
|
+ if (BeyondSection(crossingPoint, section2StartingPoint, section2EndingPoint)) return false;
|
|
|
+ if (BeyondSection(crossingPoint, section2EndingPoint, section2StartingPoint)) return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -187,6 +225,7 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
private Tuple<Point, Point> computeStrikeZone(Point targetedPoint, Point orthogonalProjection, Point cursorPosition)
|
|
|
{
|
|
|
+ if (ComputeDistance(cursorPosition, orthogonalProjection) < DEADZONE) return new Tuple<Point, Point>(targetedPoint, targetedPoint);
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
@@ -200,7 +239,14 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
private Point MoveAlongLine(Point pointToBeMoved, Point lineStartPoint, Point lineEndPoint, double distance)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ double xOffset = lineEndPoint.X - lineStartPoint.X;
|
|
|
+ double yOffset = lineEndPoint.Y - lineStartPoint.Y;
|
|
|
+ double vectorLength = ComputeDistance(lineStartPoint, lineEndPoint);
|
|
|
+ xOffset /= vectorLength;
|
|
|
+ xOffset *= distance;
|
|
|
+ yOffset /= vectorLength;
|
|
|
+ yOffset *= distance;
|
|
|
+ return new Point(pointToBeMoved.X + xOffset, pointToBeMoved.Y + yOffset);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -222,10 +268,54 @@ namespace SketchAssistantWPF
|
|
|
|
|
|
|
|
|
private Point ComputeOrthogonalProjection(Point cursorPosition, Point lastPoint, Point currentPoint)
|
|
|
+ {
|
|
|
+ double r = ComputeDistance(cursorPosition, currentPoint);
|
|
|
+ Point auxiliaryPoint = IntersectCircle(cursorPosition, r, lastPoint, currentPoint);
|
|
|
+ if (BeyondSection(auxiliaryPoint, lastPoint, currentPoint)) return currentPoint;
|
|
|
+
|
|
|
+ Point orthogonalProjection = MoveAlongLine(auxiliaryPoint, auxiliaryPoint, lastPoint, ComputeDistance(auxiliaryPoint, lastPoint) / 2);
|
|
|
+
|
|
|
+ if (BeyondSection(orthogonalProjection, currentPoint, lastPoint)) return lastPoint;
|
|
|
+
|
|
|
+ return orthogonalProjection;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Point IntersectCircle(Point cursorPosition, double r, Point lastPoint, Point currentPoint)
|
|
|
{
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private bool BeyondSection(Point pointToTest, Point sectionStartingPoint, Point sectionEndingPoint)
|
|
|
+ {
|
|
|
+ if(sectionEndingPoint.X > sectionStartingPoint.X)
|
|
|
+ {
|
|
|
+ if (pointToTest.X > sectionEndingPoint.X) return true;
|
|
|
+ }
|
|
|
+ else if(sectionEndingPoint.X < sectionStartingPoint.X)
|
|
|
+ {
|
|
|
+ if (pointToTest.X < sectionEndingPoint.X) return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (sectionEndingPoint.Y > sectionStartingPoint.Y)
|
|
|
+ {
|
|
|
+ if (pointToTest.Y > sectionEndingPoint.Y) return true;
|
|
|
+ }
|
|
|
+ else if (sectionEndingPoint.Y < sectionStartingPoint.Y)
|
|
|
+ {
|
|
|
+ if (pointToTest.Y < sectionEndingPoint.Y) return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|