Beispiel #1
0
 private void SetDestPoint3(GeoPoint p)
 {
     if (srcP3.Fixed || pair1 || pair2) // macht nur sinn bei bestimmten 3. Quellpunkt und den beiden Vorgängerpaaren
     {                                  // zunächst: Block zurücksetzen
         for (int i = 0; i < originals.Count; ++i)
         {
             block.Item(i).CopyGeometry(originals[i]);
         }
         dst3 = p;
         GeoPoint[] src = new GeoPoint[3]; // PunkteArrays für ModOp.Fit erstellen
         GeoPoint[] dst = new GeoPoint[3];
         src[0] = src1;
         dst[0] = dst1;
         src[1] = src2;
         dst[1] = dst2;
         src[2] = src3;
         dst[2] = dst3;
         try
         {
             m = ModOp.Fit(src, dst, distSw);
         }
         catch (ApplicationException)
         {
             m = ModOp.Identity;
         }
         feedBackLine.SetTwoPoints(src3, p);
         block.Modify(m);
     }
 }
Beispiel #2
0
 private void SetDestPoint1(GeoPoint p)
 {
     if (srcP1.Fixed) // macht nur Sinn bei bestimmten 1. Quellpunkt
     {                // zunächst: Block zurücksetzen
         for (int i = 0; i < originals.Count; ++i)
         {
             block.Item(i).CopyGeometry(originals[i]);
         }
         dst1  = p;
         pair1 = true;                     // dieses Punktepaar ist bestimmt
         GeoPoint[] src = new GeoPoint[1]; // PunkteArrays für ModOp.Fit erstellen
         GeoPoint[] dst = new GeoPoint[1];
         src[0] = src1;
         dst[0] = dst1;
         try
         {
             m = ModOp.Fit(src, dst, distSw);
         }
         catch (ModOpException)
         {
             m = ModOp.Identity;
         }
         feedBackLine.SetTwoPoints(src1, p);
         block.Modify(m);
     }
 }
Beispiel #3
0
        private void OnShapeFound(CompoundShape cs, Plane plane, GeoPoint fromThisPoint)
        {
            Hatch h = base.ActiveObject as Hatch;

            if (h == null)
            {
                return;            // woher kommt das (direkt beim Klicken nach dem Einfügen)
            }
            h.CompoundShape = cs;
            h.Plane         = foundOnPlane; // immer auf der ProjectionPlane arbeiten, dort wurde die Schraffur ja gefunden
            GeoPoint[] src = new GeoPoint[3];
            GeoPoint[] dst = new GeoPoint[3];
            src[0] = foundOnPlane.ToGlobal(GeoPoint2D.Origin);
            src[1] = foundOnPlane.ToGlobal(GeoPoint2D.Origin + GeoVector2D.XAxis);
            src[2] = foundOnPlane.ToGlobal(GeoPoint2D.Origin + GeoVector2D.YAxis);
            for (int i = 0; i < 3; ++i)
            {
                dst[i] = plane.Intersect(src[i], foundOnPlane.Normal);
            }
            ModOp toPlane = ModOp.Fit(src, dst, true);

            h.Modify(toPlane);
            h.Recalc();
            base.ShowActiveObject = true;
            // System.Diagnostics.Debug.WriteLine("Shape found");
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        private ModOp modOpAt(double v)
        {
            GeoPoint  loc    = along.PointAt(v);
            GeoVector deriv1 = along.DirectionAt(v);
            GeoVector dirX   = (along as IOrientation).OrientationAt(v);
            GeoVector dirZ   = deriv1;
            GeoVector dirY   = dirZ ^ dirX;
            ModOp     res    = ModOp.Translate(loc - GeoPoint.Origin) * ModOp.Fit(new GeoVector[] { baseDirX.Normalized, baseDirY.Normalized, baseDirZ.Normalized }, new GeoVector[] { dirX.Normalized, dirY.Normalized, dirZ.Normalized }) * ModOp.Translate(GeoPoint.Origin - baseLoc);
            bool      dbgort = res.IsOrthogonal;

            return(res);
        }
Beispiel #7
0
            public TangentPlane(TangentialPlanesTriangulation tpt, GeoPoint2D uv, GeoPoint location, GeoVector udirection, GeoVector vdirection)
            {
                this.tpt        = tpt;
                this.location   = location;
                this.udirection = udirection;
                this.vdirection = vdirection;
                this.normal     = udirection ^ vdirection;
                this.uv         = uv;
                // ModOp geht evtl. auch schneller:
                toThis = ModOp.Fit(location, new GeoVector[] { udirection, vdirection }, GeoPoint.Origin, new GeoVector[] { GeoVector.XAxis, GeoVector.YAxis });

                lineStartPoint = new List <GeoPoint2D>();
                lineDirection  = new List <GeoVector2D>();
                other          = new List <TangentPlane>();
            }
Beispiel #8
0
        ModOp IMovement.GetPosition(double u)
        {
            GeoVector du, dv;
            GeoPoint  loc;

            surface.DerivationAt(c2d.PointAt(u), out loc, out du, out dv);
            GeoVector2D dir2d = c2d.DirectionAt(u);
            GeoVector   ux    = dir2d.x * du + dir2d.y * dv;
            GeoVector   uz    = du ^ dv;
            GeoVector   uy    = ux ^ uz;
            ModOp       res   = ModOp.Translate(loc - GeoPoint.Origin) * ModOp.Fit(new GeoVector[] { startX.Normalized, startY.Normalized, startZ.Normalized }, new GeoVector[] { ux.Normalized, uy.Normalized, uz.Normalized }) * ModOp.Translate(GeoPoint.Origin - startPos);

            return(res);
            //return new ModOp(toUnit * ux, toUnit * uy, toUnit * uz, toUnit * loc);
        }
Beispiel #9
0
        private EntityObject ExportText(GeoObject.Text text)
        {
            System.Drawing.FontStyle fs = System.Drawing.FontStyle.Regular;
            if (text.Bold)
            {
                fs |= System.Drawing.FontStyle.Bold;
            }
            if (text.Italic)
            {
                fs |= System.Drawing.FontStyle.Italic;
            }
            System.Drawing.Font  font = new System.Drawing.Font(text.Font, 1000.0f, fs);
            netDxf.Entities.Text res  = new netDxf.Entities.Text(text.TextString, Vector2.Zero, text.TextSize * 1000 / font.Height, new TextStyle(text.Font + ".ttf"));
            ModOp toText = ModOp.Fit(GeoPoint.Origin, new GeoVector[] { GeoVector.XAxis, GeoVector.YAxis, GeoVector.ZAxis }, text.Location, new GeoVector[] { text.LineDirection.Normalized, text.GlyphDirection.Normalized, text.LineDirection.Normalized ^ text.GlyphDirection.Normalized });

            // res.TransformBy(Matrix4(toText)); // easier than setting normal and rotation
            return(res);
        }
Beispiel #10
0
        private void initSecondaryData()
        {
            GeoPoint  loc    = along.PointAt(0.0);
            GeoVector deriv1 = along.DirectionAt(0.0);

            baseLoc  = loc;
            baseDirZ = deriv1;
            if (normal.IsValid())
            {
                baseDirX = normal;
            }
            else
            {
                baseDirX = (along as IOrientation).OrientationAt(0);
            }
            baseDirY   = baseDirX ^ baseDirZ;
            toStartPos = ModOp.Fit(new GeoVector[] { baseDirX, baseDirY, baseDirZ }, new GeoVector[] { GeoVector.XAxis, GeoVector.YAxis, GeoVector.ZAxis }) * ModOp.Translate(GeoPoint.Origin - loc);
        }
Beispiel #11
0
        public HelicalSurface(ICurve basisCurve, GeoPoint axisLocation, GeoVector axisDirection, double pitch, double curveStartParameter, double curveEndParameter, GeoPoint?axisRefPoint = null) : base()
        {
            this.curveEndParameter   = curveEndParameter;
            this.curveStartParameter = curveStartParameter;
            this.pitch = pitch;
            // curveStartParameter und curveEndParameter haben folgenden Sinn:
            // der Aufrufer werwartet ein bestimmtes u/v System.
            // in u ist es die Kreisbewegung, in v ist es die Kurve (andersrum als bei SurfaceOfLinearExtrusion)
            // curveStartParameter und curveEndParameter definieren die Lage von v, die Lage von u ist durch die Ebene
            // bestimmt
            // finden der Hauptebene, in der alles stattfindet. Die ist gegeben durch die Achse und die Kurve
            Plane pln;

            if (axisRefPoint.HasValue)
            {
                GeoPoint cnt = Geometry.DropPL(axisRefPoint.Value, axisLocation, axisDirection);
                pln = new Plane(axisLocation, axisRefPoint.Value - cnt, axisDirection);
            }
            else
            {
                double ds = Geometry.DistPL(basisCurve.StartPoint, axisLocation, axisDirection);
                double de = Geometry.DistPL(basisCurve.EndPoint, axisLocation, axisDirection);
                if (ds > de && ds > Precision.eps)
                {
                    GeoPoint cnt = Geometry.DropPL(basisCurve.StartPoint, axisLocation, axisDirection);
                    pln = new Plane(axisLocation, basisCurve.StartPoint - cnt, axisDirection);
                }
                else if (de >= ds && de > Precision.eps)
                {
                    GeoPoint cnt = Geometry.DropPL(basisCurve.EndPoint, axisLocation, axisDirection);
                    pln = new Plane(axisLocation, basisCurve.EndPoint - cnt, axisDirection);
                }
                else if (basisCurve.GetPlanarState() == PlanarState.Planar)
                {
                    Plane     ppln = basisCurve.GetPlane();
                    GeoVector dirx = ppln.Normal ^ axisDirection; // richtig rum?
                    pln = new Plane(axisLocation, dirx, axisDirection);
                }
                else
                {   // es könnte sein, dass die ganze Fläche singulär ist
                    // dann kann man nichts machen, sollte aber nicht vorkommen
                    throw new SurfaceOfRevolutionException("Surface is invalid");
                }
            }
            // pln hat jetzt den Ursprung bei axisLocation, die y-Achse ist axisDirection und die x-Achse durch die
            // die Orientierung scheint mir noch fraglich, wierum wird gedreht, wierum läuft u
            // Kurve gegeben
            basisCurve2D = basisCurve.GetProjectedCurve(pln);
            // ACHTUNG "Parameterproblem": durch die Projektion der Kurve verschiebt sich bei Kreisen der Parameterraum
            // da 2D Kreise bzw. Bögen keine Achse haben und sich immer auf die X-Achse beziehen
            if (basisCurve2D is Arc2D)
            {
                curveParameterOffset = (basisCurve2D as Arc2D).StartParameter - this.curveStartParameter;
            }
            else if (basisCurve2D is BSpline2D)
            {   // beim BSpline fängt der Parameter im 3D bei knots[0] an, welches gleich this.curveStartParameter ist
                // curveParameterOffset = this.curveStartParameter;
                // wenn man einen geschlossenen Spline um eine Achse rotieren lässt
                // dann entsteht mit obiger Zeile ein Problem, mit dieser jedoch nicht:
                curveParameterOffset = (basisCurve2D as BSpline2D).Knots[0];
            }
            else
            {
                curveParameterOffset = 0.0;
            }
            toSurface = ModOp.Fit(new GeoPoint[] { GeoPoint.Origin, GeoPoint.Origin + GeoVector.XAxis, GeoPoint.Origin + GeoVector.YAxis },
                                  new GeoPoint[] { axisLocation, axisLocation + pln.DirectionX, axisLocation + pln.DirectionY }, false);
            fromSurface = toSurface.GetInverse();
        }