Ejemplo n.º 1
0
        public static DesignBody CreateBlock(Point point1, Point point2, IPart part)
        {
            List<Point> points = new List<Point>();

            points.Add(point1);
            points.Add(Point.Create(point2.X, point1.Y, point1.Z));
            points.Add(Point.Create(point2.X, point2.Y, point1.Z));
            points.Add(Point.Create(point1.X, point2.Y, point1.Z));

            return CreatePolygon(
                points,
                Plane.Create(Frame.Create(point1, Direction.DirX, Direction.DirY)),
                point2.Z - point1.Z,
                part);
        }
Ejemplo n.º 2
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            const int count = 24;

            double p             = 0.5;
            double q             = 1;
            double circleAngle   = Math.PI / 2;
            Vector inverseOffset = Vector.Create(0.5, 0, 0);

            Part mainPart = Window.ActiveWindow.Scene as Part;

            Point[] baseCirclePoints = new Point[count];
            for (int i = 0; i < count; i++)
            {
                double  u       = (double)i / count * 2 * Math.PI;
                Point[] vPoints = new Point[3];
                for (int j = 0; j < 3; j++)
                {
                    vPoints[j] = Lawson.Evaluate(PointUV.Create((double)j / 3 * 2 * Math.PI, u), p, q, circleAngle, inverseOffset, true);
                    if (j == 0)
                    {
                        baseCirclePoints[i] = vPoints[j];
                    }
                }

                Circle circle = Circle.CreateThroughPoints(
                    Plane.Create(Frame.Create(vPoints[0], Vector.Cross(vPoints[1] - vPoints[0], vPoints[2] - vPoints[0]).Direction)),
                    vPoints[0], vPoints[1], vPoints[2]
                    );

                DesignCurve.Create(mainPart, CurveSegment.Create(circle));

                //ShapeHelper.CreateTorus(circle.Frame.Origin, circle.Frame.DirZ, circle.Radius * 2,
            }

            Circle baseCircle = Circle.CreateThroughPoints(
                Plane.Create(Frame.Create(baseCirclePoints[0], Vector.Cross(baseCirclePoints[1] - baseCirclePoints[0], baseCirclePoints[2] - baseCirclePoints[0]).Direction)),
                baseCirclePoints[0], baseCirclePoints[1], baseCirclePoints[2]
                );

            DesignCurve.Create(mainPart, CurveSegment.Create(baseCircle));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempt to find convexity-sensitive angle between the normals of the adjacent faces of an edge using its midpoint. Returns a negavive angle for concave edges, 0 for tangent, or postitive for convex.
        /// </summary>
        /// <param name="edge">The Edge who's convexity is to be determined.</param>
        /// <returns></returns>
        public static double GetAngle(this Edge edge)
        {
            if (edge.Fins.Count != 2)
            {
                throw new ArgumentException("Edge must have two fins in order to have angle.");
            }

            CurveEvaluation curveEval = edge.Geometry.Evaluate((edge.Bounds.Start + edge.Bounds.End) / 2);
            Point           edgePoint = curveEval.Point;
            Direction       tangent   = curveEval.Tangent;

            Fin finA = edge.Fins.ToArray()[0];

            if (finA.IsReversed ^ finA.Edge.IsReversed)
            {
                tangent = -tangent;
            }

            Direction dirA = finA.Loop.Face.ProjectPoint(edgePoint).Normal;

            if (finA.Loop.Face.IsReversed)
            {
                dirA = -dirA;
            }

            Fin       finB = edge.Fins.ToArray()[1];
            Direction dirB = finB.Loop.Face.ProjectPoint(edgePoint).Normal;

            if (finB.Loop.Face.IsReversed)
            {
                dirB = -dirB;
            }

            double sense = Math.Asin(Math.Min(Math.Max(Vector.Dot(Direction.Cross(tangent, dirA).UnitVector, dirB.UnitVector), -1), 1)); // can be slightly out of range of [-1 ,1]

            if (Accuracy.AngleIsZero(sense))
            {
                return(0);
            }

            return(Math.Abs(AddInHelper.AngleBetween(dirA, dirB)) * (sense > 0 ? 1 : -1));
        }
        protected override bool OnClickStart(ScreenPoint cursorPos, Line cursorRay)
        {
            DesignEdge designEdge = InteractionContext.Preselection as DesignEdge;

            if (designEdge == null)
            {
                return(false);
            }

            Circle edgeCircle = (Circle)designEdge.Shape.Geometry;
            Frame  frame      = edgeCircle.Frame;
            Face   face       = designEdge.Faces.Where(f => f.Shape.Geometry is Plane).First().Shape;
            Plane  plane      = (Plane)face.Geometry;

            if (frame.DirZ == plane.Frame.DirZ ^ !face.IsReversed)
            {
                frame = Frame.Create(frame.Origin, -frame.DirZ);
            }

            double angle  = apiGroove.Angle;
            double depth  = apiGroove.Depth;
            var    points = new[] {
                Point.Create(apiGroove.InnerDiameter / 2, 0, 0),
                Point.Create(apiGroove.InnerDiameter / 2 + Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth),
                Point.Create(apiGroove.OuterDiameter / 2 - Math.Sin(angle) * depth, 0, -Math.Cos(angle) * depth),
                Point.Create(apiGroove.OuterDiameter / 2, 0, 0)
            };

            var profile = points.AsPolygon();
            var path    = new[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) };

            WriteBlock.ExecuteTask("Create Profile", () => {
                var body = Body.SweepProfile(Plane.PlaneZX, profile, path);
                body.Transform(Matrix.CreateMapping(frame));
                var cutter = DesignBody.Create(designEdge.Parent.Parent, "temp", body);
                designEdge.Parent.Shape.Subtract(new[] { cutter.Shape });
            });

            return(false);
        }
Ejemplo n.º 5
0
        static void notesImageCylindrical_Executing(object sender, EventArgs e)
        {
            Bitmap bitmap = OpenBitmap();

            if (bitmap == null)
            {
                return;
            }

            Part part = CreateImagePart();

            int    width  = bitmap.Width;
            double radius = 0.5 * stepSize / Math.Sin(Math.PI / width) * Math.PI;

            Point[] points = new Point[4];
            for (int i = 0; i < width; i++)
            {
                double angle1 = (double)i / width * 2 * Math.PI;
                double angle2 = (double)(i + 1) / width * 2 * Math.PI;
                for (int j = 0; j < bitmap.Height; j++)
                {
                    double x1 = Math.Sin(angle1) * radius;
                    double y1 = Math.Cos(angle1) * radius;
                    double z1 = j * stepSize;

                    double x2 = Math.Sin(angle2) * radius;
                    double y2 = Math.Cos(angle2) * radius;
                    double z2 = (j + 1) * stepSize;

                    points[0] = Point.Create(x1, y1, z1);
                    points[1] = Point.Create(x1, y1, z2);
                    points[2] = Point.Create(x2, y2, z2);
                    points[3] = Point.Create(x2, y2, z1);

                    DesignBody designBody = ShapeHelper.CreatePolygon(points, null, 0, part);
                    designBody.SetColor(null, GetOpaquePixel(bitmap, i, j));
                }
            }
        }
Ejemplo n.º 6
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            bool whichX = quadrantString.Substring(0, 1) == "0" ? false : true;
            bool whichY = quadrantString.Substring(1, 1) == "0" ? false : true;
            bool whichZ = quadrantString.Substring(2, 1) == "0" ? false : true;

            Command.Execute("Select");
            List <IDocObject> iDesBodies = new List <IDocObject>();

            foreach (IDesignBody iDesBody in MainPart.GetDescendants <IDesignBody>())
            {
                Point p = iDesBody.Master.Shape.GetBoundingBox(Matrix.Identity).Center;

                if ((p.X > 0 ^ whichX) && (p.Y > 0 ^ whichY) && (p.Z > 0 ^ whichZ))
                {
                    iDesBodies.Add(iDesBody);
                }
            }

            ActiveWindow.ActiveContext.Selection = iDesBodies;
            Command.Execute("IntersectTool");
        }
        public static void InitializeGraphics()
        {
            Point unit = Point.Origin + Direction.DirZ.UnitVector;
            int   jMax = sphereFacets / 2 + 1;

            for (int i = 0; i < sphereFacets; i++)
            {
                for (int j = 0; j < jMax; j++)
                {
                    Point point =
                        Matrix.CreateRotation(Frame.World.AxisZ, (double)i / sphereFacets * tau) *
                        Matrix.CreateRotation(Frame.World.AxisY, (double)j / sphereFacets * tau) *
                        unit;

                    facetVertices[i * jMax + j] = new FacetVertex(point, point.Vector.Direction);
                }
            }

            for (int i = 0; i < sphereFacets; i++)
            {
                for (int j = 0; j < jMax - 1; j++)
                {
                    int ii = (i + 1) % sphereFacets;
                    int jj = j + 1;

                    facets.Add(new Facet(
                                   i * jMax + j,
                                   ii * jMax + j,
                                   ii * jMax + jj
                                   ));
                    facets.Add(new Facet(
                                   i * jMax + j,
                                   i * jMax + jj,
                                   ii * jMax + jj
                                   ));
                }
            }
        }
Ejemplo n.º 8
0
        private static IList <IList <Point> > GetChains(FaceToolPath toolPath)
        {
            var positions = new List <IList <Point> >();

            var points = new List <Point>();

            var box   = toolPath.Face.GetBoundingBox(Matrix.Identity);
            var count = box.Size.Z / toolPath.CuttingParameters.StepOver;

            for (int i = 0; i < count; i++)
            {
                var z       = i * toolPath.CuttingParameters.StepOver;
                var plane   = Plane.Create(Frame.Create(Point.Create(0, 0, z), Direction.DirZ));
                var section = toolPath.Face.Geometry.IntersectSurface(plane);

                foreach (var iTrimmedCurve in section.Curves)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        foreach (var offsetCurve in iTrimmedCurve.Offset(plane, j * toolPath.CuttingParameters.StepOver))
                        {
                            points.AddRange(iTrimmedCurve.TessellateCurve(toolPath.CuttingParameters.Increment));
                        }
                    }
                }

                if (points.Count < 1)
                {
                    continue;
                }

                positions.Add(points);
            }

            return(positions);
        }
Ejemplo n.º 9
0
        public static DesignBody CreateTorus(Point center, Direction axis, double minorDiameter, double majorDiameter, IPart part)
        {
            double    radius = minorDiameter / 2;
            Direction dirX   = axis.ArbitraryPerpendicular;
            Direction dirY   = Direction.Cross(axis, dirX);

            Frame  profileFrame = Frame.Create(center + dirX * majorDiameter / 2, dirX, axis);
            Circle sphereCircle = Circle.Create(profileFrame, radius);

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

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

            IList <ITrimmedCurve> path = new List <ITrimmedCurve>();
            Circle sweepCircle         = Circle.Create(Frame.Create(center, dirX, dirY), radius);

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

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

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

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

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

            desBodyMaster.Transform(part.TransformToMaster);
            return(desBodyMaster);
        }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
0
        public static DesignBody CreateTorus(Point center, Direction axis, double minorDiameter, double majorDiameter, IPart part)
        {
            double radius = minorDiameter / 2;
            Direction dirX = axis.ArbitraryPerpendicular;
            Direction dirY = Direction.Cross(axis, dirX);

            Frame profileFrame = Frame.Create(center + dirX * majorDiameter / 2, dirX, axis);
            Circle sphereCircle = Circle.Create(profileFrame, radius);

            IList<ITrimmedCurve> profile = new List<ITrimmedCurve>();
            profile.Add(CurveSegment.Create(sphereCircle));

            IList<ITrimmedCurve> path = new List<ITrimmedCurve>();
            Circle sweepCircle = Circle.Create(Frame.Create(center, dirX, dirY), radius);
            path.Add(CurveSegment.Create(sweepCircle));

            Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path);
            if (body == null) {
                Debug.Fail("Sweep failed.");
                return null;
            }

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

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Torus", body);
            desBodyMaster.Transform(part.TransformToMaster);
            return desBodyMaster;
        }
Ejemplo n.º 12
0
 public Point RestPoint(Point point)
 {
     return(Point.Create(point.X, point.Y, CuttingParameters.RestZ + CuttingTool.Radius));
 }
Ejemplo n.º 13
0
 // Remove requirement that directions must be perpendicular
 public static Frame CreateFrame(Point point, Direction DirX, Direction DirY)
 {
     return(Frame.Create(point, DirX, Direction.Cross(DirX, Direction.Cross(DirY, DirX))));
 }
Ejemplo n.º 14
0
        static void notesImageSpherical_Executing(object sender, EventArgs e)
        {
            Bitmap bitmap = OpenBitmap();

            if (bitmap == null)
            {
                return;
            }

            Part part = CreateImagePart();

            int    width  = bitmap.Width;
            int    height = bitmap.Height;
            double radius = 0.5 * stepSize / Math.Sin(Math.PI / width) * Math.PI;

            Point startPoint = Point.Create(radius, 0, 0);
            Line  yAxis      = Line.Create(Point.Origin, Direction.DirY);
            Line  zAxis      = Line.Create(Point.Origin, Direction.DirZ);

            List <Point> points = new List <Point>(4);

            for (int i = 0; i < 4; i++)
            {
                points.Add(Point.Origin);
            }

            for (int i = 0; i < width; i++)
            {
                double angle1 = (double)i / width * 2 * Math.PI;
                double angle2 = (double)(i + 1) / width * 2 * Math.PI;
                for (int j = 0; j < height; j++)
                {
                    double azimuth1 = ((double)j) / height * Math.PI - Math.PI / 2;
                    double azimuth2 = ((double)j + 1) / height * Math.PI - Math.PI / 2;

                    points[0] = Matrix.CreateRotation(zAxis, angle1) * Matrix.CreateRotation(yAxis, azimuth1) * startPoint;
                    points[1] = Matrix.CreateRotation(zAxis, angle1) * Matrix.CreateRotation(yAxis, azimuth2) * startPoint;
                    points[2] = Matrix.CreateRotation(zAxis, angle2) * Matrix.CreateRotation(yAxis, azimuth2) * startPoint;
                    points[3] = Matrix.CreateRotation(zAxis, angle2) * Matrix.CreateRotation(yAxis, azimuth1) * startPoint;

                    Point?extraPoint = null;
                    if (Accuracy.Equals(points[3], points[0]))
                    {
                        extraPoint = points[0];
                        points.Remove(points[0]);
                    }
                    else
                    {
                        for (int k = 0; k < 3; k++)
                        {
                            if (Accuracy.Equals(points[k], points[k + 1]))
                            {
                                extraPoint = points[k];
                                points.Remove(points[k]);
                                break;
                            }
                        }
                    }

                    DesignBody designBody = ShapeHelper.CreatePolygon(points, null, 0, part);
                    designBody.SetColor(null, GetOpaquePixel(bitmap, i, j));

                    if (extraPoint != null)
                    {
                        points.Add(extraPoint.Value);
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public static DesignBody CreateCone(IPart part, Point point1, Point point2, double diameter1, double diameter2, bool isSurface)
 {
     return(CreateDesignBody(CreateCone(point1, point2, diameter1, diameter2, isSurface), "Cone", part));
 }
        static void notesImagePlanar_Executing(object sender, EventArgs e)
        {
            Bitmap bitmap = OpenBitmap();
            if (bitmap == null)
                return;

            Part part = CreateImagePart();

            Point[] points = new Point[4];
            for (int i = 0; i < bitmap.Width; i++) {
                for (int j = 0; j < bitmap.Height; j++) {
                    points[0] = Point.Create((i + 0) * stepSize, (j + 0) * stepSize, 0);
                    points[1] = Point.Create((i + 1) * stepSize, (j + 0) * stepSize, 0);
                    points[2] = Point.Create((i + 1) * stepSize, (j + 1) * stepSize, 0);
                    points[3] = Point.Create((i + 0) * stepSize, (j + 1) * stepSize, 0);

                    DesignBody designBody = ShapeHelper.CreatePolygon(points, Plane.PlaneXY, 0, part);
                    designBody.SetColor(null, GetOpaquePixel(bitmap, i, j));
                }
            }
        }
Ejemplo n.º 17
0
 public static DesignBody CreateCone(IPart part, Point point1, Point point2, double diameter1, double diameter2, bool isSurface)
 {
     return CreateDesignBody(CreateCone(point1, point2, diameter1, diameter2, isSurface), "Cone", part);
 }
Ejemplo n.º 18
0
 public ToolEvaluation(Point centerPoint, Point surfacePoint, Direction surfaceNormal)
 {
     CenterPoint   = centerPoint;
     SurfacePoint  = surfacePoint;
     SurfaceNormal = surfaceNormal;
 }
Ejemplo n.º 19
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;
        }
Ejemplo n.º 20
0
 public static Circle CreateCircleThroughPoints(Point p0, Point p1, Point p2)
 {
     Direction normal = Vector.Cross(p1 - p0, p2 - p0).Direction;
     return Circle.CreateThroughPoints(Plane.Create(Frame.Create(p0, normal)), p0, p1, p2);
 }
Ejemplo n.º 21
0
        public static Body CreatePolygon(IList <Point> inputPoints, Plane plane, double thickness)
        {
            List <ITrimmedCurve> profile = new List <ITrimmedCurve>();

            if (plane == null)
            {
                if (!AddInHelper.TryCreatePlaneFromPoints(inputPoints, out plane))
                {
                    return(null);
                }
            }

            Point        newPoint;
            Point        lastPoint = inputPoints[inputPoints.Count - 1].ProjectToPlane(plane);
            List <Point> points    = new List <Point>();

            foreach (Point point in inputPoints)
            {
                newPoint = point.ProjectToPlane(plane);
                if (!Accuracy.Equals(newPoint, lastPoint))
                {
                    points.Add(newPoint);
                    lastPoint = newPoint;
                }
            }

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

            Body body = null;

            try {
                if (thickness == 0)
                {
                    body = Body.CreatePlanarBody(plane, profile);
                }
                else
                {
                    body = Body.ExtrudeProfile(plane, profile, thickness);
                }
            }
            catch {
                string error = "Exception thrown creating planar body:\n";
                foreach (Point point in inputPoints)
                {
                    error += string.Format("{0}, {1}, {2}\n", point.X, point.Y, point.Z);
                }

                Debug.Assert(false, error);
            }

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

            return(body);
        }
Ejemplo n.º 22
0
        public static Circle CreateCircleThroughPoints(Point p0, Point p1, Point p2)
        {
            Direction normal = Vector.Cross(p1 - p0, p2 - p0).Direction;

            return(Circle.CreateThroughPoints(Plane.Create(Frame.Create(p0, normal)), p0, p1, p2));
        }
Ejemplo n.º 23
0
        public static ICollection <Primitive> CreateCylinderMesh(Point point1, Point point2, double diameter, int sides)
        {
            Vector heightVector = point2 - point1;

            Circle circle1 = Circle.Create(Frame.Create(point1, heightVector.Direction), diameter / 2);
            Circle circle2 = Circle.Create(Frame.Create(point2, heightVector.Direction), diameter / 2);

            var cylinderVertices = new List <FacetVertex>();
            var end1Vertices     = new List <FacetVertex>();
            var end2Vertices     = new List <FacetVertex>();

            var tempVertices = new List <Point>();  //TBD remove when we can do seletction on meshes

            double angle = 2 * Math.PI / (double)sides;

            for (int i = 0; i < sides; i++)
            {
                CurveEvaluation eval1 = circle1.Evaluate((double)i * angle);
                CurveEvaluation eval2 = circle2.Evaluate(((double)i + 0.5) * angle);

                cylinderVertices.Add(new FacetVertex(eval1.Point, (eval1.Point - circle1.Frame.Origin).Direction));
                cylinderVertices.Add(new FacetVertex(eval2.Point, (eval2.Point - circle2.Frame.Origin).Direction));

                end1Vertices.Add(new FacetVertex(eval1.Point, heightVector.Direction));
                end2Vertices.Add(new FacetVertex(eval2.Point, -heightVector.Direction));

                tempVertices.Add(eval1.Point);
                tempVertices.Add(eval2.Point);
            }

            var cylinderFacets = new List <Facet>();

            for (int i = 0; i < sides; i++)
            {
                int f00 = 2 * i;
                int f01 = f00 + 1;
                int f10 = f00 + 2 >= sides * 2 ? 0 : f00 + 2;
                int f11 = f10 + 1;

                cylinderFacets.Add(new Facet(f00, f10, f01));
                cylinderFacets.Add(new Facet(f10, f11, f01));
            }

            var end1Facets = new List <Facet>();
            var end2Facets = new List <Facet>();

            for (int i = 1; i < sides - 1; i++)
            {
                end1Facets.Add(new Facet(0, i + 1, i));
                end2Facets.Add(new Facet(0, i, i + 1));
            }

            var primitives = new List <Primitive>();

            primitives.Add(MeshPrimitive.Create(cylinderVertices, cylinderFacets));
            primitives.Add(MeshPrimitive.Create(end1Vertices, end1Facets));
            primitives.Add(MeshPrimitive.Create(end2Vertices, end2Facets));

            primitives.Add(PolylinePrimitive.Create(tempVertices)); //TBD remove

            return(primitives);
        }
Ejemplo n.º 24
0
 public CutterLocation(Point point, bool isRapid)
     : this()
 {
     Point   = point;
     IsRapid = isRapid;
 }
 public CutterLocation(Point point, bool isRapid)
     : this()
 {
     Point = point;
     IsRapid = isRapid;
 }
Ejemplo n.º 26
0
        public static ICollection <Graphic> GetGraphics(IDesignFace iDesignFace, PointUV pointUV, double span, double position, HandleTypeEnum handleType)
        {
            Debug.Assert(iDesignFace != null);

            Window activeWindow = Window.ActiveWindow;
            var    graphics     = new List <Graphic>();

            var primitives = new List <Primitive>();

            SurfaceEvaluation eval   = iDesignFace.Shape.Geometry.Evaluate(pointUV);
            Point             point  = eval.Point;
            Direction         normal = eval.Normal;

            double pixelSize      = activeWindow.ActiveContext.GetPixelSize(point);
            double shaftDiameter  = 4 * pixelSize;
            double handleDiameter = 8 * pixelSize;
            double handleHeight   = 4 * pixelSize;

            Point  startPoint          = point - (normal * (span * (position + 1) / 2 - handleHeight));
            Point  endPoint            = startPoint + normal * (span + 2 * handleHeight);
            Vector handleHalfThickness = normal * handleHeight / 2;

            bool isDrawingAll = handleType == HandleTypeEnum.All;
            var  mesh         = new List <Primitive>();
            var  style        = new GraphicStyle
            {
                EnableDepthBuffer = true,
                LineColor         = Color.DimGray,
                LineWidth         = 1,
                FillColor         = Color.DimGray
            };

            switch (handleType)
            {
            case HandleTypeEnum.All:
            case HandleTypeEnum.Shaft:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint, endPoint, shaftDiameter, 8));
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.Base;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.Base:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(point - handleHalfThickness, point + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DodgerBlue;
                style.FillColor = Color.DodgerBlue;
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.Start;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.Start:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint - handleHalfThickness, startPoint + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DarkViolet;
                style.FillColor = Color.DarkViolet;
                graphics.Add(Graphic.Create(style, mesh));

                if (isDrawingAll)
                {
                    goto case HandleTypeEnum.End;
                }
                else
                {
                    break;
                }

            case HandleTypeEnum.End:
                mesh.AddRange(ShapeHelper.CreateCylinderMesh(endPoint - handleHalfThickness, endPoint + handleHalfThickness, handleDiameter, 12));
                style.LineColor = Color.DarkViolet;
                style.FillColor = Color.DarkViolet;
                graphics.Add(Graphic.Create(style, mesh));

                break;
            }

            return(graphics);
        }
Ejemplo n.º 27
0
 public static CurveSegment AsCurveSegment(this Point point)
 {
     return(CurveSegment.Create(PointCurve.Create(point)));
 }
        static void notesImageCylindrical_Executing(object sender, EventArgs e)
        {
            Bitmap bitmap = OpenBitmap();
            if (bitmap == null)
                return;

            Part part = CreateImagePart();

            int width = bitmap.Width;
            double radius = 0.5 * stepSize / Math.Sin(Math.PI / width) * Math.PI;

            Point[] points = new Point[4];
            for (int i = 0; i < width; i++) {
                    double angle1 = (double) i / width * 2 * Math.PI;
                    double angle2 = (double) (i + 1) / width * 2 * Math.PI;
                for (int j = 0; j < bitmap.Height; j++) {
                    double x1 = Math.Sin(angle1) * radius;
                    double y1 = Math.Cos(angle1) * radius;
                    double z1 = j * stepSize;

                    double x2 = Math.Sin(angle2) * radius;
                    double y2 = Math.Cos(angle2) * radius;
                    double z2 = (j + 1) * stepSize;

                    points[0] = Point.Create(x1, y1, z1);
                    points[1] = Point.Create(x1, y1, z2);
                    points[2] = Point.Create(x2, y2, z2);
                    points[3] = Point.Create(x2, y2, z1);

                    DesignBody designBody = ShapeHelper.CreatePolygon(points, null, 0, part);
                    designBody.SetColor(null, GetOpaquePixel(bitmap, i, j));
                }
            }
        }
Ejemplo n.º 29
0
        public static ICollection <ITrimmedCurve> OffsetTowards(this ICollection <ITrimmedCurve> curves, Point point, Plane plane, double distance)
        {
            ITrimmedCurve firstCurve = curves.First();

            ITrimmedCurve[] otherCurves = curves.Skip(1).ToArray();

            bool isLeft = Vector.Dot(Vector.Cross(firstCurve.Geometry.Evaluate(0).Tangent.UnitVector, point - firstCurve.StartPoint), plane.Frame.DirZ.UnitVector) >= 0;

            return(firstCurve.OffsetChain(plane, (isLeft ? -1 : 1) * distance, otherCurves, OffsetCornerType.NaturalExtension));
        }
Ejemplo n.º 30
0
        public static DesignBody CreateCylinder(Point point1, Point point2, double diameter, IPart part)
        {
            Body body = CreateCylinder(point1, point2, diameter);

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

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Cylinder", body);
            desBodyMaster.Transform(part.TransformToMaster);
            return desBodyMaster;
        }
Ejemplo n.º 31
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));
        }
 public ToolEvaluation(Point centerPoint, Point surfacePoint, Direction surfaceNormal)
 {
     CenterPoint = centerPoint;
     SurfacePoint = surfacePoint;
     SurfaceNormal = surfaceNormal;
 }
Ejemplo n.º 33
0
        public static ICollection<Primitive> CreateCylinderMesh(Point point1, Point point2, double diameter, int sides)
        {
            Vector heightVector = point2 - point1;

            Circle circle1 = Circle.Create(Frame.Create(point1, heightVector.Direction), diameter / 2);
            Circle circle2 = Circle.Create(Frame.Create(point2, heightVector.Direction), diameter / 2);

            var cylinderVertices = new List<FacetVertex>();
            var end1Vertices = new List<FacetVertex>();
            var end2Vertices = new List<FacetVertex>();

            var tempVertices = new List<Point>();  //TBD remove when we can do seletction on meshes

            double angle = 2 * Math.PI / (double)sides;
            for (int i = 0; i < sides; i++) {
                CurveEvaluation eval1 = circle1.Evaluate((double)i * angle);
                CurveEvaluation eval2 = circle2.Evaluate(((double)i + 0.5) * angle);

                cylinderVertices.Add(new FacetVertex(eval1.Point, (eval1.Point - circle1.Frame.Origin).Direction));
                cylinderVertices.Add(new FacetVertex(eval2.Point, (eval2.Point - circle2.Frame.Origin).Direction));

                end1Vertices.Add(new FacetVertex(eval1.Point, heightVector.Direction));
                end2Vertices.Add(new FacetVertex(eval2.Point, -heightVector.Direction));

                tempVertices.Add(eval1.Point);
                tempVertices.Add(eval2.Point);
            }

            var cylinderFacets = new List<Facet>();
            for (int i = 0; i < sides; i++) {
                int f00 = 2 * i;
                int f01 = f00 + 1;
                int f10 = f00 + 2 >= sides * 2 ? 0 : f00 + 2;
                int f11 = f10 + 1;

                cylinderFacets.Add(new Facet(f00, f10, f01));
                cylinderFacets.Add(new Facet(f10, f11, f01));
            }

            var end1Facets = new List<Facet>();
            var end2Facets = new List<Facet>();
            for (int i = 1; i < sides - 1; i++) {
                end1Facets.Add(new Facet(0, i + 1, i));
                end2Facets.Add(new Facet(0, i, i + 1));
            }

            var primitives = new List<Primitive>();
            primitives.Add(MeshPrimitive.Create(cylinderVertices, cylinderFacets));
            primitives.Add(MeshPrimitive.Create(end1Vertices, end1Facets));
            primitives.Add(MeshPrimitive.Create(end2Vertices, end2Facets));

            primitives.Add(PolylinePrimitive.Create(tempVertices)); //TBD remove

            return primitives;
        }
Ejemplo n.º 34
0
 public static Point ProjectToPlane(this Point point, Plane plane)
 {
     return(plane.ProjectPoint(point).Point);
 }
Ejemplo n.º 35
0
        public static DesignBody CreateSausage(Point point1, Point point2, double diameter, IPart part)
        {
            double radius = diameter / 2;
            Vector lengthVector = point2.Vector - point1.Vector;
            Direction dirX = lengthVector.Direction;
            Direction dirY = dirX.ArbitraryPerpendicular;
            Direction dirZ = Direction.Cross(dirX, dirY);

            Frame profileFrame = Frame.Create(point1, dirX, dirY);
            Plane profilePlane = Plane.Create(profileFrame);

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

            Line axisLine = Line.Create(point1, dirX);
            profile.Add(CurveSegment.Create(axisLine, Interval.Create(-radius, lengthVector.Magnitude + radius)));

            Circle circle1 = Circle.Create(profileFrame, radius);
            profile.Add(CurveSegment.Create(circle1, Interval.Create(Math.PI / 2, Math.PI)));

            Line tangentLine = Line.Create(Matrix.CreateTranslation(dirY * radius) * point1, dirX);
            profile.Add(CurveSegment.Create(tangentLine, Interval.Create(0, lengthVector.Magnitude)));

            Circle circle2 = Circle.Create(Frame.Create(point2, dirX, dirY), radius);
            profile.Add(CurveSegment.Create(circle2, Interval.Create(0, Math.PI / 2)));

            IList<ITrimmedCurve> path = new List<ITrimmedCurve>();
            Circle sweepCircle = Circle.Create(Frame.Create(point1, dirY, dirZ), radius);
            path.Add(CurveSegment.Create(sweepCircle));

            Body body = Body.SweepProfile(Plane.Create(profileFrame), profile, path);
            if (body == null) {
                Debug.Fail("Profile was not connected, not closed, or swept along an inappropriate path.");
                return null;
            }

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sausage", body);
            desBodyMaster.Transform(part.TransformToMaster);
            return desBodyMaster;
        }
Ejemplo n.º 36
0
        public static ICollection <IList <ITrimmedCurve> > ExtractChains(this ICollection <ITrimmedCurve> curveSegments)
        {
            var profiles       = new List <List <ITrimmedCurve> >();
            var unsortedCurves = new Queue <ITrimmedCurve>(curveSegments);

            while (unsortedCurves.Count > 0)
            {
                var profile = new List <ITrimmedCurve>();
                profile.Add(unsortedCurves.Dequeue());
                Point chainStart = profile[0].StartPoint;
                Point chainEnd   = profile[0].EndPoint;

                int counter = unsortedCurves.Count;
                while (chainStart != chainEnd && counter-- > 0)
                {
                    ITrimmedCurve candidate = unsortedCurves.Dequeue();

                    if (candidate.StartPoint == chainEnd)
                    {
                        profile.Add(candidate);
                        chainEnd = candidate.EndPoint;
                        counter  = unsortedCurves.Count;
                        continue;
                    }

                    if (candidate.EndPoint == chainEnd)
                    {
                        profile.Add(candidate.GetReverse());
                        chainEnd = candidate.StartPoint;
                        counter  = unsortedCurves.Count;
                        continue;
                    }

                    if (candidate.EndPoint == chainStart)
                    {
                        profile.Insert(0, candidate);
                        chainStart = candidate.StartPoint;
                        counter    = unsortedCurves.Count;
                        continue;
                    }

                    if (candidate.StartPoint == chainStart)
                    {
                        profile.Insert(0, candidate.GetReverse());
                        chainStart = candidate.EndPoint;
                        counter    = unsortedCurves.Count;
                        continue;
                    }

                    unsortedCurves.Enqueue(candidate);
                }

                if (profile.Count > 0)
                {
                    profiles.Add(profile);
                    profile = new List <ITrimmedCurve>();
                }
            }

            return(profiles.Cast <IList <ITrimmedCurve> >().ToArray());
        }
Ejemplo n.º 37
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;
        }
Ejemplo n.º 38
0
 public static ITrimmedCurve AsITrimmedCurve(this Point point)
 {
     return(CurveSegment.Create(PointCurve.Create(point)));
 }
Ejemplo n.º 39
0
        public static DesignBody CreateSphere(Point center, double diameter, IPart part)
        {
            if (part == null)
                part = Window.ActiveWindow.ActiveContext.ActivePart;

            DesignBody desBodyMaster = DesignBody.Create(part.Master, "Sphere", CreateSphere(center, diameter));
            desBodyMaster.Transform(part.TransformToMaster);
            return desBodyMaster;
        }
Ejemplo n.º 40
0
 public static void Print(this Point point, Part part = null)
 {
     point.AsITrimmedCurve().Print(part);
 }
Ejemplo n.º 41
0
        private static Body CreateThreadBody(Face cylinderFace, double pitch, double angle, double positionOffset)
        {
            double stitchTolerance = Accuracy.LinearResolution * 1E4;

            double       radius, innerRadius, outerRadius;
            Line         axis;
            CurveSegment innerCurve, outerCurveA, outerCurveB;
            Matrix       trans;

            Cylinder cylinder = cylinderFace.Geometry as Cylinder;

            Debug.Assert(cylinder != null);
            axis = cylinder.Axis;
            Interval bounds = AxisBounds(cylinderFace, axis);

            int    threadsPerSurface  = 2;
            double threads            = bounds.Span / pitch / threadsPerSurface;
            int    threadSurfaceCount = (int)threads + 2;
            var    surfaceBounds      = Interval.Create(bounds.Start, bounds.Start + pitch * threadsPerSurface);

            //       var extendedSurfaceBounds = Interval.Create(surfaceBounds.Start - surfaceBounds.Span / threadsPerSurface, surfaceBounds.End + surfaceBounds.Span / threadsPerSurface);
            CreateUntransformedThreadCurves(cylinderFace, pitch, angle, surfaceBounds, positionOffset, out radius, out axis, out innerCurve, out outerCurveA, out outerCurveB, out trans, out innerRadius, out outerRadius);

            Body loftBodyA = Body.LoftProfiles(new[] { new[] { outerCurveA }, new[] { innerCurve } }, false, false);
            Body loftBodyB = Body.LoftProfiles(new[] { new[] { innerCurve }, new[] { outerCurveB } }, false, false);

            loftBodyA.Stitch(new[] { loftBodyB }, stitchTolerance, null);
            loftBodyA.Transform(Matrix.CreateTranslation(Direction.DirZ * -pitch * threadsPerSurface / 2));

            double threadDepth       = outerRadius - innerRadius;
            double padding           = 1.1;
            double paddedOuterRadius = innerRadius + threadDepth * padding;

            var copies = new Body[threadSurfaceCount];

            for (int i = 0; i < threadSurfaceCount; i++)
            {
                copies[i] = loftBodyA.CreateTransformedCopy(Matrix.CreateTranslation(Direction.DirZ * surfaceBounds.Span * (i + 1)));
            }

            loftBodyA.Stitch(copies, stitchTolerance, null);

            double length = bounds.Span;
            var    capA   = Body.SweepProfile(Plane.PlaneZX, new[] {
                Point.Origin,
                Point.Create(innerRadius, 0, 0),
                Point.Create(paddedOuterRadius, 0, threadDepth * Math.Tan(angle / 2) * padding),
                Point.Create(paddedOuterRadius, 0, length - threadDepth * Math.Tan(angle / 2) * padding),
                Point.Create(innerRadius, 0, length),
                Point.Create(0, 0, length)
            }.AsPolygon(), new[] { CurveSegment.Create(Circle.Create(Frame.World, 1)) });

            loftBodyA.Imprint(capA);

            capA.DeleteFaces(capA.Faces
                             .Where(f => f.Edges
                                    .Where(e => (e.Geometry is Circle && Accuracy.EqualLengths(((Circle)e.Geometry).Radius, paddedOuterRadius))
                                           ).Count() > 0).ToArray(),
                             RepairAction.None
                             );

            loftBodyA.Fuse(new[] { capA }, true, null);
            while (!loftBodyA.IsManifold)
            {
                loftBodyA.DeleteFaces(loftBodyA.Faces.Where(f => f.Edges.Where(e => e.Faces.Count == 1).Count() > 0).ToArray(), RepairAction.None);
            }

            //     loftBodyA.Faces.Select(f => loftBodyA.CopyFaces(new[] { f })).ToArray().Print();

            loftBodyA.Transform(trans);

            return(loftBodyA);
        }