Exemplo n.º 1
0
        public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
        {
            if (Precision.IsPerpendicular(pl.Normal, zAxis, false))
            {
                // two lines along the cylinder axis
                Plane               lower = new Plane(location, zAxis);
                GeoPoint2D          sp2d  = lower.Project(pl.Location);
                GeoVector2D         dir2d = lower.Project(pl.Normal).ToLeft();
                GeoPoint2D[]        ips   = Geometry.IntersectLC(sp2d, dir2d, GeoPoint2D.Origin, xAxis.Length);
                IDualSurfaceCurve[] res   = new IDualSurfaceCurve[ips.Length];
                for (int i = 0; i < ips.Length; i++)
                {
                    GeoPoint p   = lower.ToGlobal(ips[i]);
                    Line     l3d = Line.TwoPoints(p, p + zAxis);
                    res[i] = new DualSurfaceCurve(l3d, this, new Line2D(this.PositionOf(l3d.StartPoint), this.PositionOf(l3d.EndPoint)), pl, new Line2D(pl.PositionOf(l3d.StartPoint), pl.PositionOf(l3d.EndPoint)));
                }
                return(res);
            }
            else
            {
                // an ellipse
                GeoPoint2D[] cnts = pl.GetLineIntersection(location, zAxis);
                if (cnts.Length == 1)
                {   // there must be exactly one intersection
                    GeoPoint  cnt       = pl.PointAt(cnts[0]);
                    GeoVector minorAxis = pl.Normal ^ zAxis;
                    minorAxis.Length = xAxis.Length;
                    GeoVector majorAxis = minorAxis ^ pl.Normal;
                    Polynom   impl      = GetImplicitPolynomial();
                    Polynom   toSolve   = impl.Substitute(new Polynom(majorAxis.x, "u", cnt.x, ""), new Polynom(majorAxis.y, "u", cnt.y, ""), new Polynom(majorAxis.z, "u", cnt.z, ""));
                    double[]  roots     = toSolve.Roots();
                    // there must be two roots
                    majorAxis = roots[0] * majorAxis;

                    Ellipse elli = Ellipse.Construct();
                    elli.SetEllipseCenterAxis(cnt, majorAxis, minorAxis);

                    GeoPoint2D[] fpnts = new GeoPoint2D[5];
                    for (int i = 0; i < 5; i++)
                    {
                        fpnts[i] = PositionOf(elli.PointAt(i / 6.0));
                    }
                    Ellipse2D e2d = Ellipse2D.FromFivePoints(fpnts); // there should be a better way to calculate the 2d ellipse, but the following is wrong:
                    // Ellipse2D e2d = new Ellipse2D(GeoPoint2D.Origin, PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector());
                    // and principal axis doesn't yield the correct result either
                    // Geometry.PrincipalAxis(PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector(), out GeoVector2D maj, out GeoVector2D min);
                    return(new IDualSurfaceCurve[] { new DualSurfaceCurve(elli, this, e2d, pl, pl.GetProjectedCurve(elli, 0.0)) });
                }
            }
            return(new IDualSurfaceCurve[0]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.GetPlaneIntersection (PlaneSurface, double, double, double, double, double)"/>
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="umin"></param>
        /// <param name="umax"></param>
        /// <param name="vmin"></param>
        /// <param name="vmax"></param>
        /// <param name="precision"></param>
        /// <returns></returns>
        public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
        {
            IDualSurfaceCurve[] idsc = base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision);
            if (idsc == null || idsc.Length == 0)
            {
                return(idsc);
            }
            IDualSurfaceCurve dsc = idsc[0];

            if (dsc != null)
            {
                dsc = new DualSurfaceCurve(dsc.Curve3D, this, new ProjectedCurve(dsc.Curve3D, this, true, new BoundingRect(umin, vmin, umax, vmax)), dsc.Surface2, dsc.Curve2D2);
            }
            return(new IDualSurfaceCurve[] { dsc });
        }
Exemplo n.º 3
0
        IDualSurfaceCurve[] IDualSurfaceCurve.Split(double v)
        {
            ICurve[] splitted = curve3D.Split(v);
            if (splitted == null || splitted.Length != 2)
            {
                return(null);
            }
            IDualSurfaceCurve dsc1 = null, dsc2 = null;

            if (curve3D is InterpolatedDualSurfaceCurve)
            {
                dsc1 = new DualSurfaceCurve(splitted[0], surface1, (splitted[0] as InterpolatedDualSurfaceCurve).CurveOnSurface1, surface2, (splitted[0] as InterpolatedDualSurfaceCurve).CurveOnSurface2);
                dsc2 = new DualSurfaceCurve(splitted[1], surface1, (splitted[1] as InterpolatedDualSurfaceCurve).CurveOnSurface1, surface2, (splitted[1] as InterpolatedDualSurfaceCurve).CurveOnSurface2);
            }
            else
            {
                dsc1 = new DualSurfaceCurve(splitted[0], surface1, surface1.GetProjectedCurve(splitted[0], 0.0), surface2, surface2.GetProjectedCurve(splitted[0], 0.0));
                dsc2 = new DualSurfaceCurve(splitted[1], surface1, surface1.GetProjectedCurve(splitted[1], 0.0), surface2, surface2.GetProjectedCurve(splitted[1], 0.0));
            }
            return(new IDualSurfaceCurve[] { dsc1, dsc2 });

            //GeoPoint2D uv1 = surface1.PositionOf(splitted[0].EndPoint);
            //GeoPoint2D uv2 = surface2.PositionOf(splitted[0].EndPoint);
            //double u1 = curve2D1.PositionOf(uv1);
            //double u2 = curve2D2.PositionOf(uv2);

            //GeoVector2D dir12d = curve2D1.DirectionAt(u1);
            //GeoVector2D dir22d = curve2D2.DirectionAt(u2);
            //GeoVector dir1 = dir12d.x*surface1.UDirection(uv1)+ dir12d.y * surface1.VDirection(uv1);
            //GeoVector dir2 = dir22d.x*surface2.UDirection(uv2)+ dir22d.y * surface2.VDirection(uv2);
            //GeoVector dir = curve3D.DirectionAt(v);
            //// dir1 should be in direction of curve3d, dir2 in the opposite dierection
            //if (dir1 * dir < 0) curve2D1.Reverse();
            //if (dir2 * dir > 0) curve2D2.Reverse();
            //ICurve2D[] splitted1 = curve2D1.Split(u1);
            //ICurve2D[] splitted2 = curve2D2.Split(u2);
            //if (splitted1 == null || splitted1.Length != 2) return null;
            //if (splitted2 == null || splitted2.Length != 2) return null;
            //IDualSurfaceCurve dsc1 = null, dsc2 = null;
            //dsc1 = new DualSurfaceCurve(splitted[0], surface1, splitted1[0], surface2, splitted2[1]);
            //dsc2 = new DualSurfaceCurve(splitted[1], surface1, splitted1[1], surface2, splitted2[0]);
            //return new IDualSurfaceCurve[] { dsc1, dsc2 };
        }
Exemplo n.º 4
0
 public Curve2DAspect(IDualSurfaceCurve dualSurfaceCurve, bool onSurface1)
 {
     this.dualSurfaceCurve = dualSurfaceCurve;
     this.onSurface1       = onSurface1;
 }