예제 #1
0
        public void GetCurves(out IList <CurveSegment> cutterCurves, out IList <CurveSegment> rapidCurves, out IList <CurveSegment> arrowCurves)
        {
            Debug.Assert(CutterLocations != null);

            cutterCurves = new List <CurveSegment>();
            rapidCurves  = new List <CurveSegment>();
            arrowCurves  = new List <CurveSegment>();

            for (int i = 0; i < CutterLocations.Length - 1; i++)
            {
                CurveSegment curve = CurveSegment.Create(CutterLocations[i].Point, CutterLocations[i + 1].Point);
                //Debug.Assert(curve != null);
                if (curve == null)
                {
                    continue;
                }

                if (CutterLocations[i + 1].IsRapid)
                {
                    rapidCurves.Add(curve);
                }
                else
                {
                    cutterCurves.Add(curve);
                }

                if (CutterLocations[i].IsRapid && !CutterLocations[i + 1].IsRapid)
                {
                    arrowCurves.Add(curve);
                }
            }
        }
예제 #2
0
        public void AddCurve(ITrimmedCurve iTrimmedCurve)
        {
            if (iTrimmedCurve.Geometry is Line)
            {
                dxfCurves.Add(new DxfLine(iTrimmedCurve, textWriter));
                return;
            }

            if (iTrimmedCurve.Geometry is Circle)
            {
                if (iTrimmedCurve.Bounds.Span == 2 * Math.PI)
                {
                    dxfCurves.Add(new DxfCircle(iTrimmedCurve, textWriter));
                }
                else
                {
                    dxfCurves.Add(new DxfArc(iTrimmedCurve, textWriter));
                }

                return;
            }

            IList <Point> points = iTrimmedCurve.Geometry.GetPolyline(iTrimmedCurve.Bounds);

            for (int i = 0; i < points.Count - 1; i++)
            {
                dxfCurves.Add(new DxfLine(CurveSegment.Create(points[i], points[i + 1]), textWriter));
            }
        }
예제 #3
0
        private static Body CreateSphericalSegment(Point tangent, Direction normal, double radius, double halfWidth, double thickness)
        {
            Point center = tangent + normal * radius;

            radius = Math.Abs(radius);
            Plane        plane       = Plane.Create(Frame.Create(center, normal, normal.ArbitraryPerpendicular));
            Circle       circle      = Circle.Create(plane.Frame, radius);
            CurveSegment circleCurve = CurveSegment.Create(circle, Interval.Create(0, Math.Asin(halfWidth / radius)));

            Point rearCenter = tangent - normal * thickness;
            Point rearUpper  = rearCenter + plane.Frame.DirY * halfWidth;

            var profile = new List <ITrimmedCurve>();

            profile.Add(circleCurve);
            profile.Add(CurveSegment.Create(rearCenter, tangent));
            profile.Add(CurveSegment.Create(rearCenter, rearUpper));
            profile.Add(CurveSegment.Create(rearUpper, circleCurve.EndPoint));

            foreach (ITrimmedCurve curve in profile)
            {
                DesignCurve.Create(Window.ActiveWindow.Scene as Part, curve);
            }

            ITrimmedCurve path = CurveSegment.Create(Circle.Create(Frame.Create(tangent, normal), 1));

            return(Body.SweepProfile(plane, profile, new ITrimmedCurve[] { path }));
//			return Body.CreatePlanarBody(plane, new ITrimmedCurve[] { CurveSegment.Create(circle) });
//			return ShapeHelper.CreateCircle(plane.Frame, radius * 2, Window.ActiveWindow.Scene as Part).Shape.Copy();
        }
예제 #4
0
 private void CreateDesignCurveIfPointsSeparate(Part part, Point a, Point b)
 {
     if (a != b)             // compares within modeling tolerance
     {
         DesignCurve.Create(part, CurveSegment.Create(a, b));
     }
 }
예제 #5
0
        public static IList <ITrimmedCurve> AsPolygon(this IList <Point> points)
        {
            var profile = new List <ITrimmedCurve>();

            for (int i = 0; i < points.Count; i++)
            {
                ITrimmedCurve iTrimmedCurve = null;
                if (i < points.Count - 1)
                {
                    iTrimmedCurve = CurveSegment.Create(points[i], points[i + 1]);
                }
                else
                {
                    iTrimmedCurve = CurveSegment.Create(points[i], points[0]);
                }

                if (iTrimmedCurve == null) // if points are the same, the curve is null
                {
                    continue;
                }


                profile.Add(iTrimmedCurve);
            }

            if (profile.Count == 0)
            {
                return(null);
            }

            return(profile);
        }
예제 #6
0
        public static Body CreateCone(Point point1, Point point2, double diameter1, double diameter2, bool isSurface)
        {
            Vector heightVector = point2 - point1;
            Frame  frame1       = Frame.Create(point1, heightVector.Direction);
            Frame  frame2       = Frame.Create(point2, heightVector.Direction);

            var profiles = new List <ICollection <ITrimmedCurve> >();

            profiles.Add(new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(frame1, diameter1 / 2)) });
            profiles.Add(new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(frame2, diameter2 / 2)) });

            Body body = null;

            try {
                body = Body.LoftProfiles(profiles, false, true);
            }
            catch (Exception e) {
                Debug.WriteLine(e.Message);
            }

            if (body == null)
            {
                Debug.Fail("Error creating loft for cone");
                return(null);
            }

            if (isSurface)
            {
                body.DeleteFaces(body.Faces.Where(f => f.Geometry is Plane).ToArray(), RepairAction.None);
            }

            return(body);
        }
예제 #7
0
        protected override Body GetCappingBody()
        {
            Point startOuter  = StartCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale);
            Point endOuter    = EndCone.WrapPoint(0, GearData.AddendumRadius * internalGearODScale);
            Point startKnee   = StartCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module);
            Point endKnee     = EndCone.WrapPoint(0, -(1 + BevelKneeRatio) * GearData.Module);
            Point startCenter = Axis.ProjectPoint(startKnee).Point;
            Point endCenter   = Axis.ProjectPoint(endKnee).Point;

            IList <ITrimmedCurve> cappingProfile = new Point[] { startCenter, startKnee, startOuter, endOuter, endKnee, endCenter }.AsPolygon();
            IList <ITrimmedCurve> revolvePath = new ITrimmedCurve[] { CurveSegment.Create(Circle.Create(StartFrame, 1)) };

            Body cappingBody = null;

            try {
                cappingBody = Body.SweepProfile(Plane.PlaneZX, cappingProfile, revolvePath);
            }
            catch {
                foreach (ITrimmedCurve curve in cappingProfile)
                {
                    DesignCurve.Create(Part, curve);
                }
            }

            return(cappingBody);
        }
예제 #8
0
    public static MeshPrimitive GetCircularTabMesh(Point p0, Point p1, Direction normal, double angle, bool isMale)
    {
        Circle circle = GetCircularTabCircle(p0, p1, normal, angle, isMale);

        double centerParam = Math.PI / 2;

        if (!isMale)
        {
            angle       *= -1;
            centerParam += Math.PI;
        }

        ITrimmedCurve circleSegment = CurveSegment.Create(circle, Interval.Create(centerParam - angle / 2, centerParam + angle / 2));
        IList <Point> points        = circleSegment.GetPolyline();

        Debug.Assert(points.Count > 3, "Not enough points for tab faceting.");

        var facets = new List <Facet>();

        for (int i = 1; i < points.Count - 1; i++)
        {
            facets.Add(new Facet(0, i, i + 1));
        }

        return(MeshPrimitive.Create(points, normal, facets));
    }
예제 #9
0
        public static Body CreateCable(ITrimmedCurve iTrimmedCurve, double diameter)
        {
            double          radius          = diameter / 2;
            CurveEvaluation curveEvaluation = iTrimmedCurve.Geometry.Evaluate(iTrimmedCurve.Bounds.Start);
            Point           startPoint      = curveEvaluation.Point;
            Direction       dirZ            = curveEvaluation.Tangent;
            Direction       dirX            = dirZ.ArbitraryPerpendicular;
            Direction       dirY            = Direction.Cross(dirZ, dirX);

            Frame  profileFrame  = Frame.Create(startPoint, dirX, dirY);
            Circle profileCircle = Circle.Create(profileFrame, radius);

            IList <ITrimmedCurve> profile = new List <ITrimmedCurve>();

            profile.Add(CurveSegment.Create(profileCircle));

            IList <ITrimmedCurve> path = new List <ITrimmedCurve>();

            path.Add(iTrimmedCurve);

            Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path);

            if (body == null)
            {
                Debug.Fail("Sweep failed.");
                return(null);
            }

            return(body);
        }
예제 #10
0
        public static Body CreateSphere(Point center, double diameter)
        {
            double radius                 = diameter / 2;
            Frame  profileFrame           = Frame.Create(center, Direction.DirX, Direction.DirY);
            Circle sphereCircle           = Circle.Create(profileFrame, radius);
            Line   sphereRevolveLine      = Line.Create(center, Direction.DirX);
            IList <ITrimmedCurve> profile = new List <ITrimmedCurve>();

            profile.Add(CurveSegment.Create(sphereCircle, Interval.Create(0, Math.PI)));
            profile.Add(CurveSegment.Create(sphereRevolveLine, Interval.Create(-radius, radius)));

            IList <ITrimmedCurve> path = new List <ITrimmedCurve>();
            Circle sweepCircle         = Circle.Create(Frame.Create(center, Direction.DirY, Direction.DirZ), radius);

            path.Add(CurveSegment.Create(sweepCircle));

            Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path);

            if (body == null)
            {
                Debug.Fail("Sweep failed.");
                return(null);
            }

            return(body);
        }
예제 #11
0
        public static Body CreateCylinder(Point point1, Point point2, double diameter)    // TBD Merge you lazy bum
        {
            Vector heightVector = point2 - point1;
            Frame  frame        = Frame.Create(point1, heightVector.Direction);
            Plane  plane        = Plane.Create(frame);

            List <ITrimmedCurve> profile = new List <ITrimmedCurve>();

            profile.Add(CurveSegment.Create(Circle.Create(frame, diameter / 2)));

            Body body = null;

            try {
                body = Body.ExtrudeProfile(plane, profile, heightVector.Magnitude);
            }
            catch (Exception e) {
                Debug.WriteLine(e.Message);
            }

            if (body == null)
            {
                Debug.Fail("Profile was not connected, not closed, or not in order.");
                return(null);
            }

            return(body);
        }
예제 #12
0
        public static DesignBody CreateCircle(Frame frame, double diameter, IPart part)
        {
            Plane plane = Plane.Create(frame);

            List <ITrimmedCurve> profile = new List <ITrimmedCurve>();
            Circle circle = Circle.Create(frame, diameter / 2);

            profile.Add(CurveSegment.Create(circle));

            Body body = null;

            try {
                body = Body.CreatePlanarBody(plane, profile);
            }
            catch {
                Debug.Assert(false, "Exception thrown creating body");
            }

            if (body == null)
            {
                Debug.Fail("Profile was not connected, not closed, or not in order.");
                return(null);
            }

            if (part == null)
            {
                part = Window.ActiveWindow.ActiveContext.ActivePart;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Circle", body);

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
예제 #13
0
        public static CurveSegment CreateHelixAroundCurve(this ITrimmedCurve curveSegment, double turns, double radius, double pointCount)
        {
            var points = new List <Point>();

            Direction lastNormal = curveSegment.Geometry.Evaluate(curveSegment.Bounds.Start).Tangent.ArbitraryPerpendicular;

            for (int i = 0; i < pointCount; i++)
            {
                double ratio = (double)i / pointCount;
                double param = curveSegment.Bounds.Start + ratio * curveSegment.Bounds.Span;

                CurveEvaluation curveEval = curveSegment.Geometry.Evaluate(param);
                Direction       normal    = Direction.Cross(Direction.Cross(curveEval.Tangent, lastNormal), curveEval.Tangent);
                if (normal.IsZero)
                {
                    normal = lastNormal;
                }

                Point  point    = curveEval.Point;
                Matrix rotation = Matrix.CreateRotation(Line.Create(point, curveEval.Tangent), 2 * Math.PI * turns * ratio);
                point += radius * normal;
                point  = rotation * point;

                points.Add(point);
                lastNormal = normal;
            }

            return(CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, 0.000001)));
        }
예제 #14
0
        //static Plane CreatePlane(Point origin, Direction normal)
        //{
        //    return Plane.Create(Frame.Create(origin, normal));
        //}

        static DesignBody CreatePPBar(Part part)
        {
            Window window = Window.ActiveWindow;

            Debug.Assert(part != null, "part 1= null");

            double barRadius = 0.002;
            double barLenght = 0.020;

            Point pointStart = Point.Create(0, 0.03, 0.07);
            Point pointEnd   = Point.Create(0.02, 0.04, 0.09);

            DesignCurve.Create(part, CurveSegment.Create(pointStart, pointEnd));

            //Plane plane = CreatePlane(pointStart, normal);
            //DesignCurve line = DesignCurve.Create();
            //Direction direction = Direction.Equals(CurveSegment);
            //Frame frame = Frame.Create(pointStart);
            //Plane plane = Plane.Create(frame);


            Body bar = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneYZ, barRadius), barLenght);

            return(DesignBody.Create(part, "Cylinder", bar));
        }
예제 #15
0
        public static DesignBody CreateBar(Part part)
        {
            Debug.Assert(part != null, "part != null");

            double barRadius = 0.002;
            double barLenght = 0.020;

            Point pointStart = Point.Create(0, 0, 0);
            Point pointEnd   = Point.Create(0, 0.04, 0.05);

            DesignCurve.Create(part, CurveSegment.Create(pointStart, pointEnd));

            Body cylinder1 = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneZX, barRadius), barLenght);

            DesignBody.Create(part, "Cylinder1", cylinder1);


            Body cylinder2 = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneXY, barRadius), barLenght);

            DesignBody.Create(part, "Cylinder2", cylinder2);


            Body cylinder3 = Body.ExtrudeProfile(new CircleProfile(Plane.PlaneYZ, barRadius), barLenght);

            return(DesignBody.Create(part, "Cylinder3", cylinder3));
        }
예제 #16
0
        public static void CreateDashes(ITrimmedCurve curve, Part part, double dashMinSize, Layer dashLayer)
        {
            double length = curve.Length;
            int    count  = (int)Math.Floor(length / dashMinSize / 2) * 2;

            if (curve.StartPoint != curve.EndPoint)             // odd number when not closed curve
            {
                count++;
            }

            double lastParam = curve.Bounds.Start;
            double param;

            for (int i = 0; i < count; i++)
            {
                if (curve.Geometry.TryOffsetParam(lastParam, length / count, out param))
                {
                    if (i % 2 == 1)
                    {
                        DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(curve.Geometry, Interval.Create(lastParam, param)));
                        dash.Layer = dashLayer;
                    }

                    lastParam = param;
                }
            }
        }
        protected override bool OnMouseMove(ScreenPoint cursorPos, Line cursorRay, MouseButtons button)
        {
            if (button != MouseButtons.None)
            {
                return(false);
            }

            IDocObject preselection = InteractionContext.Preselection;
            DesignEdge designEdge   = preselection as DesignEdge;

            if (designEdge == null) // selection filtering is not applied if you (pre)select in the tree
            {
                return(false);
            }

            Circle edgeCircle = (Circle)designEdge.Shape.Geometry;

            CurveSegment innerCurve = CurveSegment.Create(Circle.Create(edgeCircle.Frame, apiGroove.InnerDiameter / 2));
            CurveSegment outerCurve = CurveSegment.Create(Circle.Create(edgeCircle.Frame, apiGroove.OuterDiameter / 2));

            var style = new GraphicStyle {
                LineColor = Color.DarkGray,
                LineWidth = 2
            };
            Graphic centerLine = Graphic.Create(style, new[] { CurvePrimitive.Create(innerCurve), CurvePrimitive.Create(outerCurve) });

            style = new GraphicStyle {
                LineColor = Color.White,
                LineWidth = 4
            };
            Graphic highlightLine = Graphic.Create(style, new[] { CurvePrimitive.Create(innerCurve), CurvePrimitive.Create(outerCurve) });

            Rendering = Graphic.Create(style, null, new[] { highlightLine, centerLine });
            return(false); // if we return true, the preselection won't update
        }
예제 #18
0
        private static CurveSegment TrimAndTransform(ref Matrix trans, Plane planeA, Plane planeB, CurveSegment curve)
        {
            double startParam = planeA.IntersectCurve(curve.Geometry).First().EvaluationB.Param;
            double endParam   = planeB.IntersectCurve(curve.Geometry).First().EvaluationB.Param;

            curve = CurveSegment.Create(curve.Geometry, Interval.Create(startParam, endParam));
            return(curve.CreateTransformedCopy(trans));
        }
예제 #19
0
        public void BuildSegmentedTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;

            float[]  sampled    = new float[] { 0.0f, 1.0f };
            GCHandle hSampled   = GCHandle.Alloc(sampled, GCHandleType.Pinned);
            IntPtr   ptrSampled = hSampled.AddrOfPinnedObject();

            try
            {
                CurveSegment[] segments = new CurveSegment[]
                {
                    new CurveSegment
                    {
                        x0         = -1e22f,
                        x1         = 1.0f,
                        type       = 6,
                        parameters = new double[10] {
                            1, 0, 0, 0, 0, 0, 0, 0, 0, 0
                        },
                        nGridPoints   = 0,
                        sampledPoints = IntPtr.Zero
                    },
                    new CurveSegment
                    {
                        x0            = 0.0f,
                        x1            = 1.0f,
                        type          = 0,
                        parameters    = new double[10],
                        nGridPoints   = 2,
                        sampledPoints = ptrSampled
                    },
                    new CurveSegment
                    {
                        x0            = 1.0f,
                        x1            = -1e22f,
                        type          = 6,
                        parameters    = new double[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                        nGridPoints   = 0,
                        sampledPoints = IntPtr.Zero
                    }
                };

                // Act
                using (var context = Context.Create(plugin, userData))
                    using (var toneCurve = ToneCurve.BuildSegmented(context, segments))
                    {
                        // Assert
                        Assert.IsNotNull(toneCurve);
                    }
            }
            finally
            {
                hSampled.Free();
            }
        }
예제 #20
0
        static void CreateLine(Part line)
        {
            Window window     = Window.ActiveWindow;
            Point  pointStart = Point.Create(0.10, 0.04, 0.07);
            Point  pointEnd   = Point.Create(0.02, 0.11, 0.09);

            DesignCurve.Create(line, CurveSegment.Create(pointStart, pointEnd));
            MessageBox.Show($"Line between {pointStart} and {pointEnd} will be created", "Info");
        }
예제 #21
0
    // Use this for initialization
    void Start()
    {
        var curve = track.GetComponent <CurveHandler> ().curve;

        segmentScript   = curve[segmentIndex].gameObject.GetComponent <CurveSegment> ();
        trackScript     = track.GetComponent <CurveHandler> ();
        hudManager      = HudManager.Instance;
        gameplayManager = GameplayManager.Instance;
    }
예제 #22
0
        public static ICollection <ITrimmedCurve> GetProfile(this IList <Point> points)
        {
            var iTrimmedCurves = new List <ITrimmedCurve>();

            for (int i = 0; i < points.Count; i++)
            {
                iTrimmedCurves.Add(CurveSegment.Create(points[i], points[i == points.Count - 1 ? 0 : i + 1]));
            }

            return(iTrimmedCurves);
        }
예제 #23
0
        public void AddPath(IList <Point> points, bool isClosed, double strokeWidth, Color?strokeColor, Color?fillColor)
        {
            List <ITrimmedCurve> iTrimmedCurves = new List <ITrimmedCurve>();

            for (int i = 0; i < points.Count - 1; i++)
            {
                iTrimmedCurves.Add(CurveSegment.Create(points[i], points[i + 1]));
            }

            AddPath(iTrimmedCurves, isClosed, strokeWidth, strokeColor, fillColor);
        }
예제 #24
0
        public override IEnumerable <CurveSegment> GetProfile()
        {
            Point center = Point.Origin + Direction.DirZ * Radius;
            Point top    = Point.Origin + Direction.DirZ * CuttingHeight;

            var ballArc  = CurveSegment.Create(Circle.Create(Frame.Create(center, Direction.DirX, Direction.DirZ), Radius), Interval.Create((double)3 / 4 * Const.Tau, Const.Tau));
            var sideLine = CurveSegment.Create(center + Direction.DirX * Radius, top + Direction.DirX * Radius);
            var topLine  = CurveSegment.Create(top + Direction.DirX * Radius, top);

            return(new[] { ballArc, sideLine, topLine });
        }
예제 #25
0
    void addNewCurve()
    {
        CurveSegment prev = previous;

        float        nextRadius = TrackRadius.Evaluate(curves.Count + 1);
        CurveSegment next       = new CurveSegment(prev.p1, prev.p2, prev.p3, prev.p3 + newPointOffset(), nextRadius);

        curves.Add(next);

        for (int i = (int)next.p1.z; i < (int)next.p2.z; i++)
        {
            curvesByClosestZPosition[i] = next;
        }

        var parent = new GameObject("Curve " + curves.Count);

        parent.transform.parent = curveParent;
        curveObjects.Add(parent);

        var positions  = previous.SamplePositions(DotsPerLine);
        var velocities = previous.SampleVelocities(DotsPerLine);

        int centerCycleCounter = 0;
        int centerCycle        = DotsPerLine / CenterObjectsPerLine;

        Vector3 centerDirection = Vector3.zero;

        for (int i = 0; i < positions.Length; i++)
        {
            Vector3 point = positions[i];

            centerDirection += point - (i > 0 ? positions[i - 1] : point);

            if (centerCycleCounter++ >= centerCycle)
            {
                Instantiate(CenterGameObject, point, Quaternion.Euler(positions[i - 1] - point)).transform.parent = parent.transform;
                centerDirection    = Vector3.zero;
                centerCycleCounter = 0;
            }

            CenterLine.SetPosition(CenterLine.positionCount++, point);

            float angle = 0;
            foreach (var line in Lines)
            {
                Vector3 dir = Vector3.Slerp(Vector3.forward, velocities[i].normalized, .25f);
                Vector3 dot = point + Quaternion.AngleAxis(angle, dir) * Vector3.right * next.Radius;
                line.SetPosition(line.positionCount++, dot);

                angle += 360f / Lines.Length;
            }
        }
    }
예제 #26
0
        static void CreateLines(Part multiLine)
        {
            Window window = Window.ActiveWindow;

            List <PointTarget> points = ImportingFun.LoadSampleData();

            foreach (var PointTarget in points)
            {
                //MessageBox.Show($"Line between {points[0]} and will be created");
                DesignCurve.Create(multiLine, CurveSegment.Create(Point.Create(PointTarget.xPoint, PointTarget.yPoint, PointTarget.zPoint), Point.Create(PointTarget.x2Point, PointTarget.y2Point, PointTarget.z2Point)));
            }
        }
예제 #27
0
    public void SwitchTracks(GameObject track, bool swtichFlag)
    {
        if (swtichFlag)
        {
            this.track = track;

            this.segmentIndex  = 0;
            this.positionIndex = 0;
            this.segmentScript = track.GetComponent <CurveHandler> ().curve[segmentIndex].gameObject.GetComponent <CurveSegment> ();
            this.trackScript   = track.GetComponent <CurveHandler> ();
        }
    }
예제 #28
0
        static void MultiBeamCreator(Part part)
        {
            try
            {
                //Document doc = Document.GetDocument(Settings.Default.ProjectPath + "/" + Settings.Default.ProjectName + ".scdoc");
                Document doc = Window.ActiveWindow.Document;
                Part     p   = doc.MainPart;

                int id = 0;
                List <PointLocation> pointLocations = CsvDataRead.ReadData();  // Get all beams out of file

                foreach (var location in pointLocations)
                {
                    Point startPoint = Point.Create(Double.Parse("" + (location.xPoint / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.yPoint / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.zPoint / 1000), new CultureInfo("de-DE")));
                    Point endPoint   = Point.Create(Double.Parse("" + (location.x2Point / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.y2Point / 1000), new CultureInfo("de-DE")), Double.Parse("" + (location.z2Point / 1000), new CultureInfo("de-DE")));
                    if (location.diameter != 0)
                    {
                        try
                        {
                            double diameter = location.diameter;
                            double radi     = Double.Parse("" + (location.diameter / 2000), new CultureInfo("de-DE"));

                            var lineSegment = CurveSegment.Create(startPoint, endPoint);
                            var designLine  = DesignCurve.Create(p, lineSegment);

                            Vector heightVector = endPoint - startPoint;
                            Frame  frame        = Frame.Create(startPoint, heightVector.Direction);
                            Plane  plane        = Plane.Create(frame);
                            var    profi        = new CircleProfile(plane, radi);

                            //var doc = DocumentHelper.GetActiveDocument();
                            //Document doc = Document.GetDocument(Path.GetDirectoryName("Document1"));
                            //Document doc = window.ActiveContext.Context.Document;


                            Part beamProfile = Part.CreateBeamProfile(doc, "Beam" + id, profi);

                            Beam.Create(beamProfile, designLine);
                            id += 1;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Info");
                        }
                    }
                }
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.ToString(), "Info");
            }
        }
예제 #29
0
        public static void Print(this Cone cone, Part part = null)
        {
            double startV = -Math.Cos(cone.HalfAngle) * cone.Radius;
            double endV   = 0;

            ShapeHelper.CreateRevolvedCurve(cone.Axis, CurveSegment.Create(
                                                cone.Evaluate(PointUV.Create(0, startV)).Point,
                                                cone.Evaluate(PointUV.Create(0, endV)).Point
                                                )).Print(part);

            //	Circle.Create(cone.Frame, cone.Radius).Print(part);
            //	CurveSegment.Create(cone.Evaluate(PointUV.Create(0, 0)).Point, cone.Evaluate(PointUV.Create(Math.PI / 2, 0)).Point).Print(part);
        }
        private static CurveSegment[] GenerateSegments(CurveDesc shapeDesc)
        {
            CurveSegment[]     segments = new CurveSegment[shapeDesc.NumSegments];
            IntersectionFace[] faces    = new IntersectionFace[shapeDesc.NumSegments + 1];

            float depthPerSegment = shapeDesc.StartingCuboid.Depth / shapeDesc.NumSegments;

            Quaternion yawPerSegment   = Quaternion.FromAxialRotation(Vector3.DOWN, shapeDesc.YawRotationRads / shapeDesc.NumSegments);
            Quaternion pitchPerSegment = Quaternion.FromAxialRotation(Vector3.LEFT, shapeDesc.PitchRotationRads / shapeDesc.NumSegments);
            Quaternion rollPerSegment  = Quaternion.FromAxialRotation(Vector3.FORWARD, shapeDesc.RollRotationRads / shapeDesc.NumSegments);
            Quaternion yawPitchRoll    = yawPerSegment * pitchPerSegment * rollPerSegment;

            faces[0] = new IntersectionFace(
                new Vector3(shapeDesc.StartingCuboid.GetCorner(Cuboid.CuboidCorner.FrontTopLeft), z: 0f),
                new Vector3(shapeDesc.StartingCuboid.GetCorner(Cuboid.CuboidCorner.FrontTopRight), z: 0f),
                new Vector3(shapeDesc.StartingCuboid.GetCorner(Cuboid.CuboidCorner.FrontBottomLeft), z: 0f),
                new Vector3(shapeDesc.StartingCuboid.GetCorner(Cuboid.CuboidCorner.FrontBottomRight), z: 0f)
                );
            for (int s = 1; s <= shapeDesc.NumSegments; ++s)
            {
                faces[s] = faces[s - 1].ApplyRot(yawPitchRoll);
            }

            Vector3 defaultMovement = Vector3.FORWARD * depthPerSegment;

            for (int s = 1; s <= shapeDesc.NumSegments; ++s)
            {
                for (int m = 0; m < s; ++m)
                {
                    faces[s] = faces[s].Move(defaultMovement * yawPerSegment.Subrotation(m + 1) * pitchPerSegment.Subrotation(m + 1));
                }
            }

            for (int s = 0; s < shapeDesc.NumSegments; ++s)
            {
                segments[s] = new CurveSegment(null);
                IntersectionFace backFace  = faces[s];
                IntersectionFace frontFace = faces[s + 1];
                segments[s].BackTopLeft      = backFace.TopLeft;
                segments[s].BackTopRight     = backFace.TopRight;
                segments[s].BackBottomLeft   = backFace.BottomLeft;
                segments[s].BackBottomRight  = backFace.BottomRight;
                segments[s].FrontTopLeft     = frontFace.TopLeft;
                segments[s].FrontTopRight    = frontFace.TopRight;
                segments[s].FrontBottomLeft  = frontFace.BottomLeft;
                segments[s].FrontBottomRight = frontFace.BottomRight;
            }

            return(segments);
        }
예제 #31
0
        // works like group.DrawSegment for TeX
        public static void SingleSegmentTex(this Group group, CurveSegment segment, SBMLExtension.LayoutExtension.GraphicalObject glyph, Boolean endOfLine, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            string strokewidth = group.GetStrokeWidth(rendinfo, refgroup, scale);
            Color linecolor = group.GetStrokeColor(rendinfo, refgroup);

            string strokeRef = FillColor.getStrokeRef(group, rendinfo, refgroup);
            if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curLineColor";
                FillColor.AssignColorRGBTex(linecolor, "curLineColor", writer);
            }

            string dashed = ", " + group.DashTex(group.GetDashType(refgroup));
            string segmentHead = "[line width = " + strokewidth + "pt, color = " + strokeRef + FillColor.AlphaValTex(linecolor) + dashed + "]";

                if (segment.Type == "CubicBezier")
                {
                    writer.WriteLine("\\draw{8} ({0}pt, {1}pt) .. controls ({2}pt, {3}pt) and ({4}pt, {5}pt) .. ({6}pt, {7}pt);",
                    segment.Start.X, segment.Start.Y,
                    segment.BasePoint1.X, segment.BasePoint1.Y,
                    segment.BasePoint2.X, segment.BasePoint2.Y,
                    segment.End.X, segment.End.Y,
                    segmentHead);
                }
                else if (segment.Type == "LineSegment")
                {
                    writer.WriteLine("\\draw{4} ({0}pt, {1}pt) -- ({2}pt, {3}pt);",
                    segment.Start.X, segment.Start.Y,
                    segment.End.X, segment.End.Y,
                    segmentHead);
                }

                if (endOfLine)
                {
                    group.ReactionLineEndingTex(segment, glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
                }
        }
예제 #32
0
        public static void ReactionLineStartTex(this Group group, CurveSegment segment, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            if (!string.IsNullOrEmpty(refgroup.StartHead))
            {
                PointF p1 = segment.Start.ToPointF();
                PointF p2 = segment.End.ToPointF();
                if (segment.Type != "LineSegment")
                {
                    p2 = segment.BasePoint2.ToPointF();
                }
                LineEnding ending = rendinfo.GetLineEnding(refgroup.StartHead);
                writer.WriteLine("{");
                writer.Indent += 1;

                writer.WriteLine("\\pgftransformshift{{\\pgfpoint{{ {0}pt }}{{ {1}pt }} }}",
                       p1.X.ToString(),
                       (p1.Y).ToString());

                RotationalMappingLineEndTex(ending, p1, p2, writer, refgroup);

                ending.LineEndingTex(glyph, writer, g, rendinfo, refgroup, scale, false, fontTexTable); // pass false as we have already done rotation
                writer.Indent -= 1;
                writer.WriteLine("}");
            }
        }
예제 #33
0
        private static void CreateThreadCurves(Face cylinderFace, double pitch, double angle, double positionOffset, out CurveSegment innerCurve, out CurveSegment outerCurveA, out CurveSegment outerCurveB)
        {
            double radius, innerRadius, outerRadius;
            Line axis;
            Matrix trans;

            Cylinder cylinder = cylinderFace.Geometry as Cylinder;
            Debug.Assert(cylinder != null);

            radius = cylinder.Radius;
            axis = cylinder.Axis;
            Line axisCopy = axis; //needed for out property in lambda expression

            Interval bounds = AxisBounds(cylinderFace, axisCopy);

            Interval extendedBounds = Interval.Create(bounds.Start - pitch, bounds.End + pitch);

            CreateUntransformedThreadCurves(cylinderFace, pitch, angle, extendedBounds, positionOffset, out radius, out axis, out innerCurve, out outerCurveA, out outerCurveB, out trans, out innerRadius, out outerRadius);

            var planeA = Plane.PlaneXY;
            var planeB = Plane.Create(Frame.Create(Point.Create(0, 0, bounds.Span), Direction.DirZ));

            trans = trans * Matrix.CreateTranslation(Vector.Create(0, 0, pitch));
            innerCurve = TrimAndTransform(ref trans, planeA, planeB, innerCurve);
            outerCurveA = TrimAndTransform(ref trans, planeA, planeB, outerCurveA);
            outerCurveB = TrimAndTransform(ref trans, planeA, planeB, outerCurveB);
        }
예제 #34
0
        private static void CreateUntransformedThreadCurves(Face cylinderFace, double pitch, double angle, Interval bounds, double positionOffset, out double radius, out Line axis, out CurveSegment innerCurve, out CurveSegment outerCurveA, out CurveSegment outerCurveB, out Matrix trans, out double innerRadius, out double outerRadius)
        {
            Cylinder cylinder = cylinderFace.Geometry as Cylinder;
            Debug.Assert(cylinder != null);

            radius = cylinder.Radius;
            axis = cylinder.Axis;

            double threadDepth = pitch / (2 * Math.Tan(angle / 2));

            innerRadius = radius + threadDepth * (positionOffset - 0.5);
            outerRadius = radius + threadDepth * (positionOffset + 0.5);

            int pointsPerTurn = 360;
            int pointCount = (int)(bounds.Span / pitch * pointsPerTurn);
            var outerPoints = new Point[pointCount];
            var innerPoints = new Point[pointCount];
            double s = bounds.Span;
            double a = Const.Tau * s / pitch;
            for (int i = 0; i < pointCount; i++) {
                double t = (double)i / (pointCount - 1);
                double rotation = a * t;
                double depth = s * t;
                outerPoints[i] = Point.Create(outerRadius * Math.Cos(rotation), outerRadius * Math.Sin(rotation), depth);
                innerPoints[i] = Point.Create(innerRadius * Math.Cos(rotation), innerRadius * Math.Sin(rotation), depth);
            }

            Func<double, double, Vector> Derivative =
                (t, r) => Vector.Create(-r * a * Math.Sin(a * t), r * a * Math.Cos(a * t), s);

            var outerCurve = CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, outerPoints, Accuracy.LinearResolution * 1E1, Derivative(0, outerRadius), Derivative(1, outerRadius)));
            innerCurve = CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, innerPoints, Accuracy.LinearResolution * 1E1, Derivative(0, innerRadius), Derivative(1, innerRadius)));

            var translation = Matrix.CreateTranslation(Vector.Create(0, 0, -pitch));
            var offset = Matrix.CreateTranslation(Direction.DirZ * pitch / 2);
            outerCurveA = outerCurve.CreateTransformedCopy(translation * offset);
            outerCurveB = outerCurve.CreateTransformedCopy(translation * offset.Inverse);
            innerCurve = innerCurve.CreateTransformedCopy(translation);

            trans = Matrix.CreateMapping(Frame.Create(axis.Evaluate(bounds.Start).Point, axis.Direction));
        }
예제 #35
0
 private static CurveSegment TrimAndTransform(ref Matrix trans, Plane planeA, Plane planeB, CurveSegment curve)
 {
     double startParam = planeA.IntersectCurve(curve.Geometry).First().EvaluationB.Param;
     double endParam = planeB.IntersectCurve(curve.Geometry).First().EvaluationB.Param;
     curve = CurveSegment.Create(curve.Geometry, Interval.Create(startParam, endParam));
     return curve.CreateTransformedCopy(trans);
 }
        public virtual ICollection<ITrimmedCurve> GetProfile()
        {
            baseRadius = Data.BaseRadius;
            pitchRadius = Data.PitchRadius;
            addendumRadius = Data.AddendumRadius;
            dedendumRadius = Data.DedendumRadius;

            basicInvolute = CurveSegment.Create(Data.CreateInvolute());
            offsetAngle = Data.OffsetAngle;
            involutePitchTrans = Matrix.CreateRotation(Line.Create(Point.Origin, Direction.DirZ), offsetAngle);

            curveA = basicInvolute.CreateTransformedCopy(involutePitchTrans);
            curveB = curveA.CreateTransformedCopy(mirror);

            if (Data.TopStartAngle < Data.TopEndAngle) {
                topCurve = CurveSegment.Create(Data.AddendumCircle, Interval.Create(Data.TopStartAngle, Data.TopEndAngle));
                period.Add(topCurve);
            }
            else { // involutes intersect at top land
                ICollection<IntPoint<CurveEvaluation, CurveEvaluation>> intersections = curveA.IntersectCurve(curveB.CreateTransformedCopy(Data.ToothTrans));
                Debug.Assert(intersections.Count == 1);
                if (intersections.Count != 1) {
                    curveA.Print();
                    curveB.CreateTransformedCopy(Data.ToothTrans).Print();
                }

                curveA = CurveSegment.Create(curveA.Geometry, Interval.Create(curveA.Bounds.Start, intersections.First().EvaluationA.Param));
                curveB = curveA.CreateTransformedCopy(mirror);
            }

            ICollection<IntPoint<CurveEvaluation, CurveEvaluation>> bottomIntersections = curveA.IntersectCurve(curveB);
            if (bottomIntersections.Count > 0 && bottomIntersections.First().Point.Vector.Magnitude > dedendumRadius) { // the involutes intersect at bottom land
                curveA = CurveSegment.Create(curveA.Geometry, Interval.Create(curveA.IntersectCurve(curveB).ToArray()[0].EvaluationA.Param, curveA.Bounds.End));
                period.Add(curveA);
                period.Add(curveA.CreateTransformedCopy(mirror));

                return period;
            }

            return null;
        }