public override GeoPoint2D[] GetLineIntersection(GeoPoint startPoint, GeoVector direction) { if (firstCurve is Line && secondCurve is Line) { if (Precision.SameDirection(firstCurve.StartDirection, secondCurve.StartDirection, false)) { // a simple plane PlaneSurface pls = new PlaneSurface(firstCurve.StartPoint, firstCurve.EndPoint, secondCurve.StartPoint); return(pls.GetLineIntersection(startPoint, direction)); } else { // a standard hyperbolic paraboloid with the form z = x*y as the affine transformation of this paraboloid if (toUnit.IsNull) { lock (this) { if (toUnit.IsNull) { toUnit = ModOp.Fit(new GeoPoint[] { firstCurve.StartPoint, firstCurve.EndPoint, secondCurve.StartPoint, secondCurve.EndPoint }, new GeoPoint[] { new GeoPoint(0, 0, 0), new GeoPoint(1, 0, 0), new GeoPoint(0, 1, 0), new GeoPoint(1, 1, 1) }, true); } } } // ModOp fromUnit = toUnit.GetInverse(); // Polynom hyperbolic = new Polynom(1, "xy", -1, "z"); //Polynom hyperbolic = new Polynom(2, 3); //hyperbolic.Set(1.0, new int[] { 1, 1, 0 }); //hyperbolic.Set(-1.0, new int[] { 0, 0, 1 }); // this is x*y-z==0 //ImplicitPSurface implicitHyperbolic = new ImplicitPSurface(hyperbolic); ExplicitPCurve3D explicitCurve = ExplicitPCurve3D.MakeLine(toUnit * startPoint, toUnit * direction); GeoPoint[] hypLineIsp = implicitUnitHyperbolic.Intersect(explicitCurve, out double[] uc); List <GeoPoint2D> luv = new List <GeoPoint2D>(); for (int i = 0; i < hypLineIsp.Length; i++) { double u = uc[i]; //= explicitCurve.PositionOf(hypLineIsp[i], out double dist); if (u >= -1e-6 && u <= 1 + 1e-6) { GeoPoint2D uv = new GeoPoint2D(hypLineIsp[i].x, hypLineIsp[i].y); if (BoundingRect.UnitBoundingRect.ContainsEps(uv, -0.001)) { luv.Add(uv); } } } #if DEBUG ++hitcount; if (luv.Count == 0) { } #endif return(luv.ToArray()); } } return(base.GetLineIntersection(startPoint, direction)); }
public override void Intersect(ICurve curve, BoundingRect uvExtent, out GeoPoint[] ips, out GeoPoint2D[] uvOnFaces, out double[] uOnCurve3Ds) { if (curve is IExplicitPCurve3D && firstCurve is Line && secondCurve is Line) { if (Precision.SameDirection(firstCurve.StartDirection, secondCurve.StartDirection, false)) { // a simple plane PlaneSurface pls = new PlaneSurface(firstCurve.StartPoint, firstCurve.EndPoint, secondCurve.StartPoint); // has the same uv system pls.Intersect(curve, uvExtent, out ips, out uvOnFaces, out uOnCurve3Ds); return; } else { if (toUnit.IsNull) { lock (this) { if (toUnit.IsNull) { toUnit = ModOp.Fit(new GeoPoint[] { firstCurve.StartPoint, firstCurve.EndPoint, secondCurve.StartPoint, secondCurve.EndPoint }, new GeoPoint[] { new GeoPoint(0, 0, 0), new GeoPoint(1, 0, 0), new GeoPoint(0, 1, 0), new GeoPoint(1, 1, 1) }, true); } } } ModOp fromUnit = toUnit.GetInverse(); ICurve unitCurve = curve.CloneModified(toUnit); ExplicitPCurve3D explicitCurve = (unitCurve as IExplicitPCurve3D).GetExplicitPCurve3D(); GeoPoint[] hypLineIsp = implicitUnitHyperbolic.Intersect(explicitCurve, out double[] uc); List <GeoPoint2D> luv = new List <GeoPoint2D>(); List <double> lu = new List <double>(); List <GeoPoint> lips = new List <GeoPoint>(); for (int i = 0; i < hypLineIsp.Length; i++) { double u = unitCurve.PositionOf(hypLineIsp[i]); // explicitCurve doesn't necessary have the same u system as curve if (u >= -1e-6 && u <= 1 + 1e-6) { GeoPoint2D uv = new GeoPoint2D(hypLineIsp[i].x, hypLineIsp[i].y); if (BoundingRect.UnitBoundingRect.ContainsEps(uv, -0.001)) { lu.Add(u); luv.Add(uv); lips.Add(fromUnit * hypLineIsp[i]); } } } uvOnFaces = luv.ToArray(); uOnCurve3Ds = lu.ToArray(); ips = lips.ToArray(); #if DEBUG ++hitcount; #endif return; } } base.Intersect(curve, uvExtent, out ips, out uvOnFaces, out uOnCurve3Ds); }
ExplicitPCurve3D IExplicitPCurve3D.GetExplicitPCurve3D() { return(ExplicitPCurve3D.MakeLine(startPoint, endPoint - startPoint)); }