internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF x = new PointF(100, 0); PointF[] startVector = new PointF[] { x }; Matrix rotation = new Matrix(); rotation.Rotate(startAngle); rotation.TransformVectors(startVector); PointF[] sweepVector = (PointF[])startVector.Clone(); rotation.Reset(); rotation.Rotate(sweepAngle); rotation.TransformVectors(sweepVector); rotation.Dispose(); SizeF startVectorTransformed, sweepVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0])); } else { startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0])); } // simply return the angle between the start and sweep angle, in the target system. return((int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF()))); }
/// <summary> /// Returns a value indicating whether the specified point is contained /// in the ellipse. /// </summary> /// <param name="point"></param> /// <returns></returns> public override bool Contains(PointF point) { /// TODO (CR Oct 2011): duplicated in InvariantEllipsePrimitive - should combine. if (CoordinateSystem == CoordinateSystem.Destination) { point = SpatialTransform.ConvertToSource(point); } CoordinateSystem = CoordinateSystem.Source; // Semi major/minor axes float a = Width / 2; float b = Height / 2; RectangleF rect = BoundingBox; ResetCoordinateSystem(); // Center of ellipse float xCenter = rect.Left + a; float yCenter = rect.Top + b; float x = point.X - xCenter; float y = point.Y - yCenter; return((x * x) / (a * a) + (y * y) / (b * b) <= 1); }
internal static float ConvertStartAngle(float angle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF xVector = new PointF(100, 0); Matrix rotation = new Matrix(); PointF[] angleVector = new PointF[] { xVector }; rotation.Rotate(angle); rotation.TransformVectors(angleVector); rotation.Dispose(); SizeF xVectorTransformed, angleVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToDestination(new SizeF(angleVector[0])); } else { xVectorTransformed = transform.ConvertToSource(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToSource(new SizeF(angleVector[0])); } float xRotationOffset = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); float angleTransformed = (int)Math.Round(Vector.SubtendedAngle(angleVectorTransformed.ToPointF(), PointF.Empty, xVectorTransformed.ToPointF())); // have to figure out where x-axis moved to and then return the difference between the angle // and the x-axis, where both are in 'target' coordinates. float returnAngle = angleTransformed + xRotationOffset; if (returnAngle < 0) { returnAngle += 360; } return(returnAngle); }
/// <summary> /// Performs a hit test on the <see cref="ArcPrimitive"/> at a given point. /// </summary> /// <param name="point">The mouse position in destination coordinates.</param> /// <returns> /// <b>True</b> if <paramref name="point"/> "hits" the <see cref="ArcPrimitive"/>, /// <b>false</b> otherwise. /// </returns> /// <remarks> /// A "hit" is defined as when the mouse position is <see cref="VectorGraphic.HitTestDistance"/> /// screen pixels away from any point on the arc. /// </remarks> public override bool HitTest(Point point) { this.CoordinateSystem = CoordinateSystem.Source; bool result = ArcPrimitive.HitTest( SpatialTransform.ConvertToSource(point), this.Rectangle, this.StartAngle, this.SweepAngle, this.SpatialTransform); this.ResetCoordinateSystem(); return(result); }
internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF x = new PointF(100, 0); PointF[] startVector = new PointF[] { x }; Matrix rotation = new Matrix(); rotation.Rotate(startAngle); rotation.TransformVectors(startVector); PointF[] sweepVector = (PointF[])startVector.Clone(); rotation.Reset(); rotation.Rotate(sweepAngle); rotation.TransformVectors(sweepVector); rotation.Dispose(); SizeF startVectorTransformed, sweepVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0])); } else { startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0])); sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0])); } // simply return the angle between the start and sweep angle, in the target system. return (int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF())); }
internal static float ConvertStartAngle(float angle, SpatialTransform transform, CoordinateSystem targetSystem) { PointF xVector = new PointF(100, 0); Matrix rotation = new Matrix(); PointF[] angleVector = new PointF[] { xVector }; rotation.Rotate(angle); rotation.TransformVectors(angleVector); rotation.Dispose(); SizeF xVectorTransformed, angleVectorTransformed; if (targetSystem == Graphics.CoordinateSystem.Destination) { xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToDestination(new SizeF(angleVector[0])); } else { xVectorTransformed = transform.ConvertToSource(new SizeF(xVector)); angleVectorTransformed = transform.ConvertToSource(new SizeF(angleVector[0])); } float xRotationOffset = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector)); float angleTransformed = (int)Math.Round(Vector.SubtendedAngle(angleVectorTransformed.ToPointF(), PointF.Empty, xVectorTransformed.ToPointF())); // have to figure out where x-axis moved to and then return the difference between the angle // and the x-axis, where both are in 'target' coordinates. float returnAngle = angleTransformed + xRotationOffset; if (returnAngle < 0) returnAngle += 360; return returnAngle; }