public double MaxAnglePerpendicular(ref clsPoint3d maxAV1, ref clsPoint3d maxAV2) { double a; double maxA; clsPoint3d py, pz; clsPoint3d p1 = null, p2 = null, p3 = null, p4 = null; if (MaxAngle(ref p3, ref p4) < myTol) { return(0); } pz = new clsPoint3d(0, 0, 1.0); py = pz.Cross(p3); if (IsSameDbl(py.Length, 0)) { py = pz.Cross(p4); } if (IsSameDbl(py.Length, 0)) { return(0); } py.Normalise(); maxA = 0; for (int j = 0; j <= myCameraPoints.Count - 2; j++) { for (int k = j + 1; k <= myCameraPoints.Count - 1; k++) { p1 = myCameraPoints[j]; p1 = py * py.Dot(p1) + pz * pz.Dot(p1); p1.Normalise(); p2 = myCameraPoints[k]; p2 = py * py.Dot(p2) + pz * pz.Dot(p2); p2.Normalise(); a = Acos(p1.Dot(p2)); if (Abs(a) > maxA) { maxA = Abs(a); maxAV1 = p1.Copy(); maxAV2 = p2.Copy(); } } } return(maxA); }
public double DistanceToLine(clsLine3d l2) { //Perpendicular distance between 3d lines. Limited to the line segments. double myNormalDist; clsPoint3d v1; clsPoint3d v2; clsPoint3d M; double m2; clsPoint3d R; clsPoint3d P21; double t1; double t2; clsPoint3d Q1; clsPoint3d Q2; //Find the actual point on this line where the perpendicular distance hits. If it is off the line, then find the minimum distance between the end points v1 = new clsPoint3d(DX(), DY(), DZ()); v1.Normalise(); v2 = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ()); v2.Normalise(); P21 = new clsPoint3d(l2.X1 - X1, l2.X1 - X1, l2.X1 - X1); M = v2.Cross(v1); m2 = M.Dot(M); if (m2 < mdlGeometry.myTol) { return(DistanceToPoint(l2.P1)); } //Parallel myNormalDist = Abs(P21.Dot(M)) / Sqrt(m2); //Perpendicular distance R = P21.Cross(M); R.Scale(1 / m2); t1 = R.Dot(v2); Q1 = P1 + t1 * v1; if (t1 < 0) { Q1 = P1; } if (t1 > Length) { Q1 = P2; } t2 = R.Dot(v1); Q2 = l2.P1 + t2 * v2; if (t2 < 0) { Q2 = l2.P1; } if (t2 > l2.Length) { Q2 = l2.P2; } return(Q1.Dist(Q2)); }
public void RotateAboutLine(clsLine3d l1, double theta) { clsPoint3d p1 = default(clsPoint3d); clsPoint3d p2 = default(clsPoint3d); clsPoint3d p2a = default(clsPoint3d); clsPoint3d p2b = default(clsPoint3d); clsPoint3d p3 = default(clsPoint3d); clsLine3d l2 = default(clsLine3d); if (l1.IsOnLine(this)) { return; } //Setup a coordinate system with X running along l1 and the origin at l1.p2 l2 = new clsLine3d(l1.P2.Copy(), Copy()); p1 = new clsPoint3d(l1.DX(), l1.DY(), l1.DZ()); p1.Length = 1; p2 = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ()); p2a = new clsPoint3d(l2.DX(), l2.DY(), l2.DZ()); p2.Length = 1; p3 = p1.Cross(p2); p3.Length = 1; p2 = p1.Cross(p3); p2.Length = 1; if (p2.Dot(p2a) < 0) { p2.Scale(-1); } p2b = new clsPoint3d(p1.Dot(p2a), p2.Dot(p2a), p3.Dot(p2a)); p2b.RotateAboutX(theta); myX = l1.X2 + p2b.x * p1.x + p2b.y * p2.x + p2b.z * p3.x; myY = l1.Y2 + p2b.x * p1.y + p2b.y * p2.y + p2b.z * p3.y; myZ = l1.Z2 + p2b.x * p1.z + p2b.y * p2.z + p2b.z * p3.z; }
public static clsPoint3d ProjectPointOntoPlaneAlongZ(clsPoint p, clsLine3d l1) { clsLine3d v1 = new clsLine3d(); double u = 0; double r = 0; double z = 0; clsPoint3d p1 = new clsPoint3d(); v1 = new clsLine3d(new clsPoint3d(0, 0, 0), new clsPoint3d(0, 0, 1)); u = v1.Dot(l1); //This is the length of the normal vector, measured in the vertical direction p1 = new clsPoint3d(p.X - l1.X1, p.Y - l1.Y1, 0 - l1.Z1); r = p1.Dot(l1.DP()); //r is the distance of our point to the nearest point on the plane //r = v1.Dot(myV) z = r / u; //z is the vertical distance of our point to the plane. It is sign sensitive - positive is above the plane. return(new clsPoint3d(p.X, p.Y, -z)); }