Beispiel #1
0
        private static ProfileDetails CalcPrismProfile(this ObjectPart.PrimitiveShape.Decoded shape)
        {
            /* Prism has cut start at 0,0.5 */
            var profile = new ProfileDetails();

            double startangle = 2 * Math.PI * shape.ProfileBegin;
            double endangle   = 2 * Math.PI * shape.ProfileEnd;
            double stepangle  = (endangle - startangle) / 60;
            var    angles     = shape.CalcBaseAngles(startangle, endangle, stepangle);

            if (shape.IsHollow)
            {
                /* we calculate two points */
                double  profileHollow = shape.ProfileHollow * 0.5;
                Vector3 startPoint    = Vector3.UnitX * 0.5;
                foreach (var angle in angles)
                {
                    Vector3 outerDirectionalVec = CalcTrianglePoint(angle);
                    Vector3 innerDirectionalVec;

                    switch (shape.HoleShape)
                    {
                    case PrimitiveProfileHollowShape.Triangle:
                    case PrimitiveProfileHollowShape.Same:
                        innerDirectionalVec = outerDirectionalVec * profileHollow;
                        break;

                    case PrimitiveProfileHollowShape.Circle:
                        /* circle is simple as we are calculating with such objects */
                        innerDirectionalVec = startPoint.Rotate2D_XY(angle) * profileHollow;
                        break;

                    case PrimitiveProfileHollowShape.Square:
                        innerDirectionalVec = CalcTopEdgedSquare(angle) * profileHollow;
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    /* inner path is reversed */
                    profile.Vertices.Add(outerDirectionalVec);
                    profile.Vertices.Insert(0, innerDirectionalVec);
                }
                /* no center point here, even though we can have path cut */
                profile.IsOpenHollow = shape.IsOpen;
            }
            else
            {
                /* no hollow, so it becomes simple */
                foreach (var angle in angles)
                {
                    Vector3 directionalVec = CalcTrianglePoint(angle);
                    profile.Vertices.Add(directionalVec);
                }
                if (shape.IsOpen)
                {
                    profile.Vertices.Add(new Vector3(0, 0, 0));
                }
                else
                {
                    profile.Vertices.RemoveAt(profile.Vertices.Count - 1);
                }
            }

            return(profile);
        }
Beispiel #2
0
        private static ProfileDetails CalcBoxProfile(this ObjectPart.PrimitiveShape.Decoded shape)
        {
            /* Box has cut start at 0.5,-0.5 */
            var profile = new ProfileDetails();

            double        startangle = 2 * Math.PI * shape.ProfileBegin;
            double        endangle   = 2 * Math.PI * shape.ProfileEnd;
            double        stepangle  = (endangle - startangle) / 60;
            List <double> angles     = shape.CalcBaseAngles(startangle, endangle, stepangle);

            if (shape.IsHollow)
            {
                /* we calculate two points */
                Vector3 startPoint = START_VECTOR_BOX * 0.5;
                foreach (var angle in angles)
                {
                    Vector3 outerDirectionalVec = startPoint.Rotate2D_XY(angle);
                    Vector3 innerDirectionalVec = outerDirectionalVec;

                    /* outer normalize on single component to 0.5, simplifies algorithm */
                    outerDirectionalVec = outerDirectionalVec.CalcPointToSquareBoundary(1);

                    switch (shape.HoleShape)
                    {
                    case PrimitiveProfileHollowShape.Triangle:
                        innerDirectionalVec = CalcTrianglePoint(angle).Rotate2D_XY(-2.3561944901923448) * shape.ProfileHollow * 0.5;
                        break;

                    case PrimitiveProfileHollowShape.Circle:
                        /* circle is simple as we are calculating with such objects */
                        innerDirectionalVec *= shape.ProfileHollow;
                        break;

                    case PrimitiveProfileHollowShape.Same:
                    case PrimitiveProfileHollowShape.Square:
                        /* inner normalize on single component to 0.5 * hollow */
                        innerDirectionalVec = innerDirectionalVec.CalcPointToSquareBoundary(shape.ProfileHollow);
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    /* inner path is reversed */
                    profile.Vertices.Add(outerDirectionalVec);
                    profile.Vertices.Insert(0, innerDirectionalVec);
                }
                /* no center point here, even though we can have path cut */
                profile.IsOpenHollow = shape.IsOpen;
            }
            else
            {
                /* no hollow, so it becomes simple */
                Vector3 startPoint = START_VECTOR_BOX * 0.5;
                foreach (var angle in angles)
                {
                    Vector3 directionalVec = startPoint.Rotate2D_XY(angle);
                    /* normalize on single component to 0.5, simplifies algorithm */
                    directionalVec = directionalVec.CalcPointToSquareBoundary(1);
                    profile.Vertices.Add(directionalVec);
                }
                if (shape.IsOpen)
                {
                    profile.Vertices.Add(new Vector3(0, 0, 0));
                }
                else
                {
                    profile.Vertices.RemoveAt(profile.Vertices.Count - 1);
                }
            }

            return(profile);
        }