Example #1
0
        public static DesignBody CreatePolygon(IList <Point> inputPoints, double thickness, IPart part)
        {
            Plane plane;

            if (!AddInHelper.TryCreatePlaneFromPoints(inputPoints, out plane))
            {
                throw new ArgumentException("Points don't form plane");
            }

            return(CreatePolygon(inputPoints, plane, thickness, part));
        }
Example #2
0
        public static Body CreateRevolvedCurve(Line axis, ITrimmedCurve curve)
        {
            Point point = curve.Geometry.Evaluate(curve.Bounds.Middle()).Point;

            Debug.Assert(Accuracy.LengthIsPositive((axis.ProjectPoint(point).Point - point).Magnitude));

            Plane plane   = null;
            bool  success = AddInHelper.TryCreatePlaneFromPoints(new Point[] {
                axis.Origin,
                axis.Evaluate(1).Point,
                point
            }, out plane);

            Debug.Assert(success, "Could not create plane through points.");

            Point axisStart = axis.ProjectPoint(curve.StartPoint).Point;
            Point axisEnd   = axis.ProjectPoint(curve.EndPoint).Point;

            var profile = new List <ITrimmedCurve>();

            profile.Add(curve);

            if (axisStart != curve.StartPoint)
            {
                profile.Add(CurveSegment.Create(axisStart, curve.StartPoint));
            }

            if (axisEnd != curve.EndPoint)
            {
                profile.Add(CurveSegment.Create(axisEnd, curve.EndPoint));
            }

            profile.Add(CurveSegment.Create(axisStart, axisEnd));

            try {
                Body body = Body.SweepProfile(Plane.PlaneZX, profile, new ITrimmedCurve[] {
                    CurveSegment.Create(Circle.Create(Frame.World, 1))
                });

                body.DeleteFaces(body.Faces.Where(f => f.Geometry is Plane).ToArray(), RepairAction.None);
                return(body);
            }
            catch {
                return(null);
            }
        }
Example #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));
        }
Example #4
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);
        }