internal static Line2D GetParallelLine(Point p1, Point p2, Point directionPoint, double offset) { Point2D linePoint1 = new Point2D(); Point2D linePoint2 = new Point2D(); double dx = p1.X - p2.X; double dy = p1.Y - p2.Y; double leght = Math.Sqrt((dx) * (dx) + (dy) * (dy)); // Determine the direction of the offset. offset *= GetPointPosition(p1, p2, directionPoint); // This is the parallel line linePoint1.X = (p1.X - offset * (dy) / leght); linePoint2.X = (p2.X - offset * (dy) / leght); linePoint1.Y = (p1.Y + offset * (dx) / leght); linePoint2.Y = (p2.Y + offset * (dx) / leght); Line2D parallelLine = new Line2D(linePoint1, linePoint2); return parallelLine; }
/// <summary> /// Updates the position of the line. /// </summary> /// <param name="line">The new line.</param> internal void Update(Line2D line) { Check.NotNull(line, "line"); this.Point1.X = line.Point1.X; this.Point1.Y = line.Point1.Y; this.Point2.X = line.Point2.X; this.Point2.Y = line.Point2.Y; }
/// <summary> /// Creates a new instance of <see cref="TangibleObject"/>. /// </summary> /// <param name="point1">The first point.</param> /// <param name="point2">The second point.</param> /// <param name="point3">The third point. This should be the direction point.</param> internal TangibleObject(TouchPoint point1, TouchPoint point2, TouchPoint point3) { Check.NotNull(point1, "point1"); Check.NotNull(point2, "point2"); Check.NotNull(point3, "point3"); // Validate the points if (point1.IsDirectionPoint || point2.IsDirectionPoint) throw new InvalidOperationException("The first two points should not be direction points!"); if (!point3.IsDirectionPoint) throw new InvalidOperationException("No direction point specified!"); Points = new TouchPointCollection(); Points.AddPoint(point1); Points.AddPoint(point2); Points.AddPoint(point3); // Create the bottom line _bottomLine = new TouchLine(point1, point2); // Calculate the top line _topLine = CalculateTopLine(_bottomLine, point3); _topLine.Owner = this; // Set the owner of the points. //Points.ForEach(p => p.Owner = this); foreach (var point in Points) { point.Owner = this; point.Changed += OnPointChanged; } }