Example #1
0
 /// <summary>
 /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.SameGeometry (BoundingRect, ISurface, BoundingRect, double, out ModOp2D)"/>
 /// </summary>
 /// <param name="thisBounds"></param>
 /// <param name="other"></param>
 /// <param name="otherBounds"></param>
 /// <param name="precision"></param>
 /// <param name="firstToSecond"></param>
 /// <returns></returns>
 public override bool SameGeometry(BoundingRect thisBounds, ISurface other, BoundingRect otherBounds, double precision, out ModOp2D firstToSecond)
 {
     firstToSecond = ModOp2D.Null;
     if (other is PlaneSurface)
     {
         PlaneSurface second = other as PlaneSurface;
         GeoPoint     p      = PointAt(thisBounds.GetCenter());
         if (Math.Abs(second.Plane.Distance(p)) > precision)
         {
             return(false);
         }
         p = second.PointAt(otherBounds.GetCenter());
         if (Math.Abs(Plane.Distance(p)) > precision)
         {
             return(false);
         }
         if (Precision.SameDirection(Normal, second.Normal, false))
         {
             GeoPoint2D[] src = new GeoPoint2D[] { GeoPoint2D.Origin, new GeoPoint2D(1, 0), new GeoPoint2D(0, 1) };
             GeoPoint2D[] dst = new GeoPoint2D[3];
             for (int i = 0; i < 3; ++i)
             {
                 dst[i] = second.PositionOf(PointAt(src[i]));
             }
             firstToSecond = ModOp2D.Fit(src, dst, true);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(base.SameGeometry(thisBounds, other, otherBounds, precision, out firstToSecond));
 }
        /// <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)
        {
            if (Precision.IsPerpendicular(pl.Plane.Normal, direction, false))
            {   // Ebene, die parallel zur Auszugsrichtung liegt. Es entstehen Linien
                List <IDualSurfaceCurve> res = new List <IDualSurfaceCurve>();
                double[] cpar = basisCurve.GetPlaneIntersection(pl.Plane);
                for (int i = 0; i < cpar.Length; i++)
                {
                    // von 0..1 auf startParameter..endParameter umrechnen
                    double pos = curveStartParameter + cpar[i] * (curveEndParameter - curveStartParameter);
                    if (pos >= umin && pos <= umax)
                    {
                        ICurve           c3d = FixedU(pos, vmin, vmax);
                        Line2D           l2d = new Line2D(new GeoPoint2D(pos, vmin), new GeoPoint2D(pos, vmax));
                        DualSurfaceCurve dsc = new DualSurfaceCurve(c3d, this, l2d, pl, c3d.GetProjectedCurve(pl.Plane));
                        res.Add(dsc);
                    }
                }
                return(res.ToArray());
                //return new IDualSurfaceCurve[] { };
                //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision); // stürzt ab mit 50050020_012_1_FMZ.stp
            }
            else if (Precision.SameDirection(direction, pl.Plane.Normal, false))
            {
                if (basisCurve.GetPlanarState() == PlanarState.Planar && Precision.SameDirection(direction, basisCurve.GetPlane().Normal, false))
                {
                    Plane cp = basisCurve.GetPlane();
                    if (!Precision.SameNotOppositeDirection(cp.Normal, direction))
                    {
                        cp = new Plane(cp.Location, cp.DirectionY, cp.DirectionX);
                    }
                    double           v   = cp.Distance(pl.Plane.Location) / direction.Length;
                    Line2D           l2d = new Line2D(new GeoPoint2D(curveStartParameter, v), new GeoPoint2D(curveEndParameter, v));
                    DualSurfaceCurve dsc = new DualSurfaceCurve(basisCurve.CloneModified(ModOp.Translate(v * direction)), this, l2d, pl, basisCurve.GetProjectedCurve(pl.Plane));
                    return(new IDualSurfaceCurve[] { dsc });
                }
            }
            // keine Lösung gefunden
            double[] upos = basisCurve.GetSavePositions();
            InterpolatedDualSurfaceCurve.SurfacePoint[] sp = new InterpolatedDualSurfaceCurve.SurfacePoint[upos.Length];
            for (int i = 0; i < upos.Length; ++i)
            {
                GeoPoint     p0  = basisCurve.PointAt(upos[i]);
                double       pos = curveStartParameter + upos[i] * (curveEndParameter - curveStartParameter);
                GeoPoint2D[] ips = pl.GetLineIntersection(p0, direction);
                if (ips.Length == 1)
                {
                    GeoPoint p3d = pl.PointAt(ips[0]);
                    double   v   = Geometry.LinePar(p0, direction, p3d);
                    sp[i] = new InterpolatedDualSurfaceCurve.SurfacePoint(p3d, new GeoPoint2D(pos, v), ips[0]);
                }
            }
            InterpolatedDualSurfaceCurve idsc = new InterpolatedDualSurfaceCurve(this, pl, sp, true);

            return(new IDualSurfaceCurve[] { idsc.ToDualSurfaceCurve() });
            //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision);
        }
Example #3
0
        /// <summary>
        /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.CopyData (ISurface)"/>
        /// </summary>
        /// <param name="CopyFrom"></param>
        public override void CopyData(ISurface CopyFrom)
        {
            PlaneSurface cc = CopyFrom as PlaneSurface;

            if (cc != null)
            {
                this.fromUnitPlane = cc.fromUnitPlane;
                this.toUnitPlane   = cc.toUnitPlane;
            }
        }
        /// <summary>
        /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.HitTest (BoundingCube, out GeoPoint2D)"/>
        /// </summary>
        /// <param name="bc"></param>
        /// <param name="uv"></param>
        /// <returns></returns>
        public override bool HitTest(BoundingCube bc, out GeoPoint2D uv)
        {
            Plane        p  = new Plane(GeoPoint.Origin, direction);
            PlaneSurface ps = new PlaneSurface(p);
            ICurve2D     c  = basisCurve.GetProjectedCurve(p);

            GeoPoint[]   points   = bc.Points;
            GeoPoint2D[] points2D = new GeoPoint2D[8];
            for (int i = 0; i < 8; ++i)
            {
                points2D[i] = ps.PositionOf(points[i]);
            }
            // does c hit the polygon?
            int[,] l = bc.LineNumbers;
            for (int k = 0; k < 12; ++k)
            {
                int      i  = l[k, 0];
                int      j  = l[k, 1];
                ICurve2D c2 = new Line2D(points2D[i], points2D[j]);
                if (c2.Length > 0)
                {
                    GeoPoint2DWithParameter[] list = c.Intersect(c2);
                    for (int m = 0; m < list.Length; ++m)
                    {
                        GeoPoint2D d0 = list[m].p;
                        double     d1 = (points2D[i] - d0).Length;
                        double     d2 = (points2D[j] - d0).Length;
                        double     d3 = (points2D[i] - points2D[j]).Length;
                        if (Math.Abs(d1 + d2 - d3) < Precision.eps)
                        {
                            if (d3 < Precision.eps)
                            {
                                throw new Exception();
                            }
                            GeoPoint gp = points[i] + (d1 / d3) * (points[j] - points[i]);
                            uv = PositionOf(gp);
                            return(true);
                        }
                    }
                }
            }
            // is c in the polygon?
            GeoPoint e   = ps.PointAt(c.EndPoint);
            bool     res = (bc.Interferes(e, direction, bc.Size * 1e-8, false));

            if (res)
            {   // nur berechnen, wenn auch gültig
                uv = PositionOf(e);
            }
            else
            {
                uv = GeoPoint2D.Origin;
            }
            return(res);
        }
        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]);
        }
Example #6
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 });
        }
Example #7
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)
        {
            PlaneSurface plm = pl.GetModified(toUnitPlane) as PlaneSurface;
            GeoVector    dir = GeoVector.ZAxis ^ plm.Normal.Normalized; // Richtung der Linie

            dir = toUnitPlane * (Normal.Normalized ^ pl.Normal.Normalized);
            GeoVector2D dir2d = new GeoVector2D(dir.x, dir.y);

            if (dir.Length > 0.0)
            {
                GeoPoint2D[] ip = plm.GetLineIntersection(GeoPoint.Origin, new GeoVector(dir.y, -dir.x, dir.z)); // dir.z müsste ohnehin 0 sein
                if (ip.Length > 0)
                {
                    GeoPoint   org = plm.PointAt(ip[0]);
                    GeoPoint2D org2d = new GeoPoint2D(org.x, org.y);
                    double     lmin, lmax;
                    if (Math.Abs(dir.x) > Math.Abs(dir.y))
                    {   // eher waagrecht
                        lmin = (umin - org.x) / dir.x;
                        lmax = (umax - org.x) / dir.x;
                    }
                    else
                    {
                        lmin = (vmin - org.y) / dir.y;
                        lmax = (vmax - org.y) / dir.y;
                    }
                    ICurve2D curve2d1 = new Line2D(org2d + lmin * dir2d, org2d + lmax * dir2d);
                    Line     line     = Line.Construct();
                    line.SetTwoPoints(PointAt(curve2d1.StartPoint), PointAt(curve2d1.EndPoint));
                    ICurve2D curve2d2 = new Line2D(pl.PositionOf(line.StartPoint), pl.PositionOf(line.EndPoint));
                    return(new DualSurfaceCurve[] { new DualSurfaceCurve(line, this, curve2d1, pl, curve2d2) });
                }
            }
            return(new DualSurfaceCurve[] { });
            //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax);
        }
Example #8
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)
 {
     return(base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision));
 }