/// <summary> /// Calculate Euclidean distance between two points. /// </summary> /// /// <param name="anotherPoint">Point to calculate distance to.</param> /// /// <returns>Returns Euclidean distance between this point and /// <paramref name="anotherPoint"/> points.</returns> /// public float DistanceTo( IntPoint anotherPoint ) { int dx = X - anotherPoint.X; int dy = Y - anotherPoint.Y; return (float) System.Math.Sqrt( dx * dx + dy * dy ); }
public void GetAngleBetweenVectorsTest( int sx, int sy, int ex1, int ey1, int ex2, int ey2, float expectedAngle ) { IntPoint startPoint = new IntPoint( sx, sy ); IntPoint vector1end = new IntPoint( ex1, ey1 ); IntPoint vector2end = new IntPoint( ex2, ey2 ); float angle = GeometryTools.GetAngleBetweenVectors( startPoint, vector1end, vector2end ); Assert.AreEqual( expectedAngle, angle, 0.00001f ); }
public void GetAngleBetweenLinesTest( int sx1, int sy1, int ex1, int ey1, int sx2, int sy2, int ex2, int ey2, float expectedAngle ) { IntPoint line1start = new IntPoint( sx1, sy1 ); IntPoint line1end = new IntPoint( ex1, ey1 ); IntPoint line2start = new IntPoint( sx2, sy2 ); IntPoint line2end = new IntPoint( ex2, ey2 ); float angle = GeometryTools.GetAngleBetweenLines( line1start, line1end, line2start, line2end ); Assert.AreEqual( expectedAngle, angle, 0.00001f ); }
// Set image to display by the control public int SetImage(Bitmap image) { leftEdges.Clear(); rightEdges.Clear(); topEdges.Clear(); bottomEdges.Clear(); hulls.Clear(); quadrilaterals.Clear(); selectedBlobID = 0; this.image = Accord.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb); imageWidth = this.image.Width; imageHeight = this.image.Height; blobCounter.ProcessImage(this.image); blobs = blobCounter.GetObjectsInformation(); GrahamConvexHull grahamScan = new GrahamConvexHull(); foreach (Blob blob in blobs) { List<IntPoint> leftEdge = new List<IntPoint>(); List<IntPoint> rightEdge = new List<IntPoint>(); List<IntPoint> topEdge = new List<IntPoint>(); List<IntPoint> bottomEdge = new List<IntPoint>(); // collect edge points blobCounter.GetBlobsLeftAndRightEdges(blob, out leftEdge, out rightEdge); blobCounter.GetBlobsTopAndBottomEdges(blob, out topEdge, out bottomEdge); leftEdges.Add(blob.ID, leftEdge); rightEdges.Add(blob.ID, rightEdge); topEdges.Add(blob.ID, topEdge); bottomEdges.Add(blob.ID, bottomEdge); // find convex hull List<IntPoint> edgePoints = new List<IntPoint>(); edgePoints.AddRange(leftEdge); edgePoints.AddRange(rightEdge); List<IntPoint> hull = grahamScan.FindHull(edgePoints); hulls.Add(blob.ID, hull); List<IntPoint> quadrilateral = null; // find quadrilateral if (hull.Count < 4) { quadrilateral = new List<IntPoint>(hull); } else { quadrilateral = PointsCloud.FindQuadrilateralCorners(hull); } quadrilaterals.Add(blob.ID, quadrilateral); // shift all points for vizualization IntPoint shift = new IntPoint(1, 1); PointsCloud.Shift(leftEdge, shift); PointsCloud.Shift(rightEdge, shift); PointsCloud.Shift(topEdge, shift); PointsCloud.Shift(bottomEdge, shift); PointsCloud.Shift(hull, shift); PointsCloud.Shift(quadrilateral, shift); } UpdatePosition(); Invalidate(); return blobs.Length; }
/// <summary> /// Division operator - divides coordinates of the specified point by scalar value. /// </summary> /// /// <param name="point">Point to divide coordinates of.</param> /// <param name="factor">Division factor.</param> /// /// <returns>Returns new point which coordinates equal to coordinates of /// the specified point divided by specified value.</returns> /// public static IntPoint Divide( IntPoint point, int factor ) { return new IntPoint( point.X / factor, point.Y / factor ); }
/// <summary> /// Multiplication operator - multiplies coordinates of the specified point by scalar value. /// </summary> /// /// <param name="point">Point to multiply coordinates of.</param> /// <param name="factor">Multiplication factor.</param> /// /// <returns>Returns new point which coordinates equal to coordinates of /// the specified point multiplied by specified value.</returns> /// public static IntPoint Multiply( IntPoint point, int factor ) { return new IntPoint( point.X * factor, point.Y * factor ); }
/// <summary> /// Subtraction operator - subtracts scalar from the specified point. /// </summary> /// /// <param name="point">Point to decrease coordinates of.</param> /// <param name="valueToSubtract">Value to subtract from coordinates of the specified point.</param> /// /// <returns>Returns new point which coordinates equal to coordinates of /// the specified point decreased by specified value.</returns> /// public static IntPoint Subtract( IntPoint point, int valueToSubtract ) { return new IntPoint( point.X - valueToSubtract, point.Y - valueToSubtract ); }
/// <summary> /// Addition operator - adds scalar to the specified point. /// </summary> /// /// <param name="point">Point to increase coordinates of.</param> /// <param name="valueToAdd">Value to add to coordinates of the specified point.</param> /// /// <returns>Returns new point which coordinates equal to coordinates of /// the specified point increased by specified value.</returns> /// public static IntPoint Add( IntPoint point, int valueToAdd ) { return new IntPoint( point.X + valueToAdd, point.Y + valueToAdd ); }
/// <summary> /// Subtraction operator - subtracts values of two points. /// </summary> /// /// <param name="point1">Point to subtract from.</param> /// <param name="point2">Point to subtract.</param> /// /// <returns>Returns new point which coordinates equal to difference of corresponding /// coordinates of specified points.</returns> /// public static IntPoint Subtract( IntPoint point1, IntPoint point2 ) { return new IntPoint( point1.X - point2.X, point1.Y - point2.Y ); }
/// <summary> /// Addition operator - adds values of two points. /// </summary> /// /// <param name="point1">First point for addition.</param> /// <param name="point2">Second point for addition.</param> /// /// <returns>Returns new point which coordinates equal to sum of corresponding /// coordinates of specified points.</returns> /// public static IntPoint Add( IntPoint point1, IntPoint point2 ) { return new IntPoint( point1.X + point2.X, point1.Y + point2.Y ); }
public static Rg.Point3d ToRhPoint(this Ac.IntPoint input, int transposition = 0) { return(new Rg.Point3d(input.X, transposition - input.Y, 0)); }