/// <summary> /// Perimeter of a rectangle /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> /// <param name="D"></param> /// <returns></returns> public static double Perimeter(Caliper A, Caliper B, Caliper C, Caliper D) { //A & C intersect //Top right PointF one = Utility.PointOfIntersection(A, C); //A & D intersect //Top left PointF two = Utility.PointOfIntersection(A, D); //B & C //Bottom right PointF three = Utility.PointOfIntersection(B, C); //B & D //Bottom left PointF four = Utility.PointOfIntersection(B, D); //Only need d1 and d3. double d1 = EuclideanDistance(one, three); double d2 = EuclideanDistance(three, four); double d3 = EuclideanDistance(four, two); double d4 = EuclideanDistance(two, one); return(d1 + d2 + d3 + d4); }
/// <summary> /// Point where two lines intersect is given by /// //x = (b2 - b1) / ( m1 - m2) ... then plug in for y /// </summary> /// <param name="One"></param> /// <param name="Two"></param> /// <returns></returns> public static PointF PointOfIntersection(Caliper One, Caliper Two) { double x; double y; //0 slope Horizontal line if ((One.Slope - Two.Slope) == 0) { x = 0; // y = b y = One.B; } //Vertical line else if (One.Slope == 12345679) { x = One.CenterPoint.X; y = Two.Slope * x + Two.B; } //Vertical Line else if (Two.Slope == 123456789) { x = Two.CenterPoint.X; y = One.Slope * x + One.B; } else { x = (Two.B - One.B) / (One.Slope - Two.Slope); //y = mx + b y = One.Slope * x + One.B; } return(new PointF((float)x, (float)y)); }
public RectangleStruct(Caliper C1, Caliper C2, Caliper C3, Caliper C4, double minimum) { this.C1 = C1; this.C2 = C2; this.C3 = C3; this.C4 = C4; //one of hte two will be right it doesnt matter which because we nly call this with one //of the two algorithm this.MinimumArea = minimum; this.MinimumPerim = minimum; }
public void SetC1(Caliper Cal) { C1 = new Caliper(); double d1 = Cal.CenterPoint.X; double d2 = Cal.CenterPoint.Y; C1.CenterPoint = new PointF((float)d1, (float)d2); d1 = Cal.P1.X; d2 = Cal.P1.Y; C1.P1 = new PointF((float)d1, (float)d2); d1 = Cal.P2.X; d2 = Cal.P2.Y; C1.P2 = new PointF((float)d1, (float)d2); }
public void SetC4(Caliper Cal) { C4 = new Caliper(); double d1 = Cal.CenterPoint.X; double d2 = Cal.CenterPoint.Y; C4.CenterPoint = new PointF((float)d1, (float)d2); d1 = Cal.P1.X; d2 = Cal.P1.Y; C4.P1 = new PointF((float)d1, (float)d2); d1 = Cal.P2.X; d2 = Cal.P2.Y; C4.P2 = new PointF((float)d1, (float)d2); }