public clsLine TangentToPointUp(clsPoint pt1) { //Goes on a transition up double a; double x; clsLine l1 = new clsLine(); if (pt1.X < Centre.X + mdlGeometry.myTol) { return(null); } a = Atan((pt1.Y - Centre.Y) / Abs((pt1.X - Centre.X))); x = Radius / pt1.Dist(Centre); if (x >= 1) { return(null); } a = a - Acos(x); l1.P1.X = Centre.X + Radius * Cos(a); l1.P1.Y = Centre.Y + Radius * Sin(a); l1.P2.X = pt1.X; l1.P2.Y = pt1.Y; return(l1); }
static int GetSquareForDatum(ARParam arParams, double[,] model, clsPoint pt) { var cpt = ModelToImageSpace(arParams, model, pt); var pt1 = ModelToImageSpace(arParams, model, new clsPoint(pt.x - 8, pt.y - 8)); var pt2 = ModelToImageSpace(arParams, model, new clsPoint(pt.x + 8, pt.y - 8)); var pt3 = ModelToImageSpace(arParams, model, new clsPoint(pt.x + 8, pt.y + 8)); var pt4 = ModelToImageSpace(arParams, model, new clsPoint(pt.x - 8, pt.y + 8)); var l1 = new clsLine(pt1, pt2); var l2 = new clsLine(pt2, pt3); var l3 = new clsLine(pt3, pt4); var l4 = new clsLine(pt4, pt1); double d = 100; var l = new clsLine(cpt, new clsPoint(cpt.x - 1, cpt.y - 1)); var p1 = l.Intersect(l1); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } p1 = l.Intersect(l2); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } p1 = l.Intersect(l3); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } p1 = l.Intersect(l4); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } l = new clsLine(cpt, new clsPoint(cpt.x + 1, cpt.y - 1)); p1 = l.Intersect(l1); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } p1 = l.Intersect(l2); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } p1 = l.Intersect(l3); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } p1 = l.Intersect(l4); if (p1 != null && p1.Dist(cpt) < d) { d = p1.Dist(cpt); } return((int)(d / Sqrt(2.0) + 0.5)); }
public bool IsOnShortLine(clsPoint pt1, double aTol = 0, bool excludeEnds = false) { clsLine l1 = default(clsLine); clsLine l2 = default(clsLine); double d = 0; if (aTol == 0) { aTol = mdlGeometry.myTol; } if (Abs(pt1.Dist(this)) > aTol) { return(false); } l1 = new clsLine(P1, pt1); l2 = Copy(); l2.Normalise(); d = l1.Dot(l2); if (d < -aTol) { return(false); } if (d > Length + aTol) { return(false); } if (excludeEnds && (P1 == pt1 | P2 == pt1)) { return(false); } return(true); }
public double DistanceToNearestSegment(clsPoint p1, ref int nSeg, ref int nPt, int avoidPt1 = -1, int avoidPt2 = -1, int includePt = -1) { int i; int j; clsLine l1; double d; double minD; //Find the point nearest nPt = GetNearestPointIndex(p1); //Find the segment closest to the point to add (ignore riser segments) nSeg = 0; minD = 10000; for (i = 0; i <= NumPoints; i++) { if ((i != avoidPt1 & i != avoidPt2) & (includePt == -1 || (i == includePt | i == includePt - 1 | (includePt == 0 & i == NumPoints)))) { j = i + 1; if (j > NumPoints) { j = 0; } l1 = new clsLine(Point(i), Point(j)); d = l1.DistanceToShortLine(p1); if (d < minD) { minD = d; nSeg = i; } } } return(minD); }
//Moves the line public void Move(clsLine l2) { X1 = X1 + l2.DX(); X2 = X2 + l2.DX(); Y1 = Y1 + l2.DY(); Y2 = Y2 + l2.DY(); }
public bool IsPointInside(clsPoint p1) { //Uses the "winding number" to check if a point lies inside or outside the sketch int i; double a; double a1; clsLine l1; clsLine l2; a = 0; l1 = new clsLine(p1, Point(0)); for (i = 1; i <= myPoints.Count - 1; i++) { l2 = new clsLine(p1, Point(i)); a1 = mdlGeometry.Angle(l1, l2); a = a + a1; l1 = l2.Copy(); } l2 = new clsLine(p1, Point(0)); a1 = mdlGeometry.Angle(l1, l2); a = a + a1; if (mdlGeometry.IsSameDbl(a, 0)) { return(false); } return(true); }
public clsPoint PointFromLambda(double l) { clsLine l1 = default(clsLine); l1 = Copy(); l1.Scale(l); return(l1.P2); }
public clsPoint DistanceAlongLine(double d) { clsLine l1 = default(clsLine); l1 = Copy(); l1.Normalise(); return(new clsPoint(X1 + d * l1.DX(), Y1 + d * l1.DY())); }
public double Dist(clsLine l1) { clsLine l2 = default(clsLine); clsLine l3 = default(clsLine); l2 = l1.Normal(); l3 = new clsLine(l1.P1, this); return(Abs(l2.Dot(l3))); }
public clsPoint IntersectShortLines(clsLine l1) { //Both truncated if (IntersectShortLine1(l1) == null) { return(null); } return(IntersectShortLine2(l1)); }
public bool IsSame(clsLine l1) { //Is this line the same as another (up to orientation)? if ((P1 == l1.P1 & P2 == l1.P2) | (P1 == l1.P2 & P2 == l1.P1)) { return(true); } return(false); }
public static double Dist(clsPoint p1, clsLine l1) { //+ve for outside the wall, left handed; Also, +ve for above straight. clsLine l2 = new clsLine(); clsLine l3 = new clsLine(); l2 = (clsLine)l1.Normal(); l3 = new clsLine(l1.P1, p1); return(l2.Dot(l3)); }
public clsLine Normal() { clsLine functionReturnValue = default(clsLine); //Special routine to help with finding "signed" distance of points to lines double theta = 0; theta = Angle; functionReturnValue = new clsLine(0, 0, 0, 1); functionReturnValue.Rotate(Angle); return(functionReturnValue); }
public clsPoint IntersectQuick(clsLine l1) { //Both infinite double lambda = 0; if (Abs((X2 - X1) * (l1.Y1 - l1.Y2) + (Y2 - Y1) * (l1.X2 - l1.X1)) < mdlGeometry.myTol / 10) { return(null); } //No intersection lambda = ((l1.X2 - X1) * (l1.Y1 - l1.Y2) + (l1.Y2 - Y1) * (l1.X2 - l1.X1)) / ((X2 - X1) * (l1.Y1 - l1.Y2) + (Y2 - Y1) * (l1.X2 - l1.X1)); return(new clsPoint(X1 + lambda * (X2 - X1), Y1 + lambda * (Y2 - Y1))); }
public static clsPoint ProjectPoint(clsPoint p1, clsLine l1) { double d = 0; clsPoint pt1 = new clsPoint(); clsLine l2 = new clsLine(); d = Dist(p1, l1); pt1 = p1.Copy(); l2 = (clsLine)l1.Normal(); l2.Normalise(); l2.Scale(-d); pt1.Move(l2.P2.X, l2.P2.Y); return(pt1); }
public clsPoint FilletPoint() { clsLine l1; clsLine l2; clsPoint p1; clsPoint p2; p1 = StartPoint(); p2 = Tangent(Angle1); l1 = new clsLine(p1.X, p1.Y, p1.X + p2.X, p1.Y + p2.Y); p1 = EndPoint(); p2 = Tangent(Angle2); l2 = new clsLine(p1.X, p1.Y, p1.X + p2.X, p1.Y + p2.Y); return(l1.Intersect(l2)); }
public List <clsPoint> Intersect(clsLine l1, bool sortByDistToL1P1 = false) { List <clsPoint> myPts = new List <clsPoint>(); int i; int j; clsLine l2; clsPoint p1; double d1; double d2; for (i = 0; i <= NumPoints; i++) { j = i + 1; if (j > NumPoints) { j = 0; } l2 = new clsLine(Point(i), Point(j)); p1 = l1.IntersectShortLine1(l2); if (p1 != null) { myPts.Add(p1); } } if (sortByDistToL1P1) { for (i = 0; i <= myPts.Count - 2; i++) { d1 = myPts[i].Dist(l1.P1); for (j = i + 1; j <= myPts.Count - 1; j++) { d2 = myPts[j].Dist(l1.P1); if (d2 < d1) { p1 = myPts[i]; myPts[i] = myPts[j]; myPts[j] = p1; } } } } return(myPts); }
public clsPoint IntersectShortLine1(clsLine l1) { //Leaves Me as infinite, but truncates l1 double l = 0; clsPoint pt1 = default(clsPoint); pt1 = Intersect(l1); if (pt1 == null) { return(null); } l = l1.Lambda(pt1); if (l < 0 | l > 1) { return(null); } return(pt1); }
public clsPoint IntersectShortLine2(clsLine l1) { //Truncates Me but leaves l1 infinite double l = 0; clsPoint pt1 = default(clsPoint); pt1 = Intersect(l1); if (pt1 == null) { return(null); } l = Lambda(pt1); if (l < 0 | l > 1) { return(null); } return(pt1); }
public clsLine TangentToPoint(clsPoint pt1) { double a; double x; clsLine l1 = new clsLine(); if (pt1.X == Centre.X) { if (pt1.Y > Centre.Y) { a = PI / 2; } else { a = 3 * PI / 2; } } else { a = Atan((pt1.Y - Centre.Y) / Abs((pt1.X - Centre.X))); if (pt1.X > Centre.X) { a = PI - a; } } x = Radius / pt1.Dist(Centre); if (x >= 1) { return(null); } a = a - (Atan(-x / Sqrt(-x * x + 1)) + 2 * Atan(1)); l1.P1.X = Centre.X - Radius * Cos(a); l1.P1.Y = Centre.Y + Radius * Sin(a); l1.P2.X = pt1.X; l1.P2.Y = pt1.Y; //l1.p2.y = l1.p1.y - (pt1.x - l1.p1.x) * Tan((180 - a) * Pi / 180) Angle2 = a; return(l1); }
public static clsLine LinePointToTangent(clsPoint p1, clsCircle c1) { double a = 0; double b = 0; double r = 0; double d = 0; clsLine l1 = new clsLine(); clsPoint p2 = new clsPoint(); r = c1.Radius; d = p1.Dist(c1.Centre); if (d < r) { return(null); } a = Asin(r / d); l1 = new clsLine(p1, c1.Centre); b = l1.Angle; p2 = c1.Point(PI / 2 + a + b); return(new clsLine(p1, p2)); }
public clsLine TangentToPointDown(clsPoint pt1) { //Goes on the downside of a transition down double a; double x; clsLine l1; if (pt1.x > Centre.x - mdlGeometry.myTol) { return(null); } a = Atan((Centre.y - pt1.y) / Abs((Centre.x - pt1.x))); x = Radius / pt1.Dist(Centre); if (x >= 1) { return(null); } a = Acos(x) - a; l1 = new clsLine(pt1.Copy(), new clsPoint(Centre.x - Radius * Cos(a), Centre.y + Radius * Sin(a))); return(l1); }
public bool Overlaps(clsLine aLine, double aTol = 0) { clsLine l1 = default(clsLine); clsPoint p3 = default(clsPoint); clsPoint p4 = default(clsPoint); if (aTol == 0) { aTol = mdlGeometry.myTol; } l1 = aLine.Copy(); if ((!IsOnLine(l1.P1, aTol)) | (!IsOnLine(l1.P2, aTol))) { return(false); } if (Dot(l1) < 0) { l1.Reverse(); } p3 = l1.P1; p4 = l1.P2; if (P1 == p3) { return(true); } if (P1 == p4 | P2 == p3) { return(false); } if (IsOnShortLine(p4, aTol)) { return(true); } if (l1.IsOnShortLine(P1, aTol) | l1.IsOnShortLine(P2, aTol)) { return(true); } return(false); }
public bool SelfIntersects() { int i; int i1; int j; int j1; int n; clsLine l1; clsLine l2; for (i = 0; i <= NumPoints - 2; i++) { i1 = i + 1; l1 = new clsLine(Point(i), Point(i1)); n = NumPoints; if (i == 0) { n = n - 1; } //Don't need to intersect the first line with the last, because they touch for (j = i + 2; j <= n; j++) { j1 = j + 1; if (j1 > NumPoints) { j1 = 0; } l2 = new clsLine(Point(j), Point(j1)); if (l1.IntersectShortLines(l2) != null) { return(true); } } } return(false); }
public clsPoint Intersect(clsLine l1, bool getSecond = false) { double a = 0; double b = 0; double c = 0; double xc = 0; double yc = 0; double lambda1 = 0; double lambda2 = 0; if (mdlGeometry.Dist(Centre, l1) > Radius) { return(null); } xc = Centre.x; yc = Centre.y; a = Pow((l1.X2 - l1.X1), 2) + Pow((l1.Y2 - l1.Y1), 2); b = 2 * ((l1.X2 - l1.X1) * (l1.X1 - xc) + (l1.Y2 - l1.Y1) * (l1.Y1 - yc)); c = Pow((l1.X1 - xc), 2) + Pow((l1.Y1 - yc), 2) - Pow((Radius), 2); lambda1 = (-b + Sqrt(Abs(Pow(b, 2) - 4 * a * c))) / (2 * a); lambda2 = (-b - Sqrt(Abs(Pow(b, 2) - 4 * a * c))) / (2 * a); if (getSecond == false) { if (lambda2 < lambda1 & lambda2 > 0) { lambda1 = lambda2; } } else { if (lambda1 < lambda2) { lambda1 = lambda2; } } return(new clsPoint(l1.X1 + lambda1 * (l1.X2 - l1.X1), l1.Y1 + lambda1 * (l1.Y2 - l1.Y1))); }
public double VerticalHeight(clsPoint pt1) { //Returns the height of the line where is passes over p1 clsLine l1 = default(clsLine); clsLine l2 = default(clsLine); double d = 0; double d1 = 0; double d2 = 0; l1 = new clsLine(P1.X, P1.Y, P2.X, P2.Y); if (l1.IsOnLine(pt1) == false) { return(0); } d1 = l1.Length; l1.Normalise(); l2 = new clsLine(l1.P1, pt1); d2 = l1.Dot(l2); d = d2 / d1; return(P1.Z + (P2.Z - P1.Z) * d); }
public clsPoint Intersect(clsLine l1) { //Limits the intersection to the arc clsPoint aPt; aPt = base.Intersect(l1); if (aPt == null) { return(null); } if (PointLiesOnArc(aPt) == false) { aPt = base.Intersect(l1, true); if (aPt == null) { return(null); } if (PointLiesOnArc(aPt) == false) { return(null); } } return(aPt); }
public clsPoint Intersect(clsCircle c1, bool firstSolution) { double a = 0; clsLine l1 = default(clsLine); if (mdlGeometry.Dist(Centre, c1.Centre) > Radius + c1.Radius) { return(null); } if (mdlGeometry.Dist(Centre, c1.Centre) < Abs(Radius - c1.Radius)) { return(null); } l1 = new clsLine(Centre.Copy(), c1.Centre.Copy()); a = Acos((Radius * Radius + l1.Length * l1.Length - c1.Radius * c1.Radius) / (2 * Radius * l1.Length)); //Cosine rule if (firstSolution == false) { a = -a; } l1.Rotate(a); l1.Length = Radius; return(l1.P2); }
//Public Function IntersectShortLine1(ByVal l1 As clsLine) As clsPoint 'Leaves Me as infinite, but truncates l1 // Dim lambda As Double // If Abs((l1.X2 - l1.X1) * (Y1 - Y2) + (l1.Y2 - l1.Y1) * (X2 - X1)) < mdlGeometry.myTol Then Return Nothing 'No intersection // lambda = ((X2 - l1.X1) * (Y1 - Y2) + (Y2 - l1.Y1) * (X2 - X1)) / ((l1.X2 - l1.X1) * (Y1 - Y2) + (l1.Y2 - l1.Y1) * (X2 - X1)) // If lambda < 0 Or lambda > 1 Then Return Nothing // Return New clsPoint(l1.X1 + lambda * (l1.X2 - l1.X1), l1.Y1 + lambda * (l1.Y2 - l1.Y1)) //End Function //Public Function IntersectShortLine2(ByVal l1 As clsLine) As clsPoint 'Truncates Me but leaves l1 infinite // Dim lambda As Double // If Abs((X2 - X1) * (l1.Y1 - l1.Y2) + (Y2 - Y1) * (l1.X2 - l1.X1)) < mdlGeometry.myTol Then Return Nothing 'No intersection // lambda = ((l1.X2 - X1) * (l1.Y1 - l1.Y2) + (l1.Y2 - Y1) * (l1.X2 - l1.X1)) / ((X2 - X1) * (l1.Y1 - l1.Y2) + (Y2 - Y1) * (l1.X2 - l1.X1)) // If lambda < 0 Or lambda > 1 Then Return Nothing // Return New clsPoint(X1 + lambda * (X2 - X1), Y1 + lambda * (Y2 - Y1)) //End Function public clsPoint Intersect(clsLine l1) { //Both infinite. More accurate that IntersectQuick double l = 0; clsLine l2 = default(clsLine); clsLine l3 = default(clsLine); if (Length < mdlGeometry.myTol | l1.Length < mdlGeometry.myTol) { return(null); } l2 = Copy(); l3 = l1.Copy(); l2.Length = 1000; l3.Length = 1000; if (Abs(((l2.X2 - l2.X1) * (l3.Y1 - l3.Y2) + (l2.Y2 - l2.Y1) * (l3.X2 - l3.X1))) < mdlGeometry.myTol / 10) { return(null); } //No intersection l = ((l3.X2 - l2.X1) * (l3.Y1 - l3.Y2) + (l3.Y2 - l2.Y1) * (l3.X2 - l3.X1)) / ((l2.X2 - l2.X1) * (l3.Y1 - l3.Y2) + (l2.Y2 - l2.Y1) * (l3.X2 - l3.X1)); return(new clsPoint(l2.X1 + l * (l2.X2 - l2.X1), l2.Y1 + l * (l2.Y2 - l2.Y1))); }
public bool IsOnHalfLine(clsPoint pt1, double aTol = 0) { clsLine l1 = default(clsLine); clsLine l2 = default(clsLine); double d = 0; if (aTol == 0) { aTol = mdlGeometry.myTol; } if (Abs(pt1.Dist(this)) > aTol) { return(false); } l1 = new clsLine(P1, pt1); l2 = Copy(); l2.Normalise(); d = l1.Dot(l2); if (d < -aTol) { return(false); } return(true); }