예제 #1
0
        public static Circular <V> Pie(float width, float height, float stepAngle,
                                       float startAngle, float endAngle)
        {
            if (startAngle > endAngle)
            {
                throw new ArgumentException("Start angle must be bigger than end angle");
            }
            var fullCircle = startAngle == endAngle;

            if (fullCircle)
            {
                endAngle += MathHelper.TwoPi;
            }
            var vertCount = (int)Math.Ceiling((endAngle - startAngle) / stepAngle) + (fullCircle ? 1 : 2);
            var normal    = new Vec3(0f, 0f, 1f);
            var vertices  = new V[vertCount];

            vertices [0] = VertexHelpers.New <V> (new Vec3(0f), normal);
            var angle = startAngle;

            for (var i = 1; i < vertCount; i++)
            {
                var pos = new Vec3(width * (float)Math.Cos(angle), height * (float)Math.Sin(angle), 0f);
                vertices [i] = VertexHelpers.New <V> (pos, normal);
                angle        = Math.Min(angle + stepAngle, endAngle);
            }
            return(new Circular <V> (vertices, fullCircle));
        }
예제 #2
0
        public static Triangle <V> Scalene(float leftOffset, float rightOffset, float height)
        {
            var normal = new Vec3(0f, 0f, 1f);

            return(new Triangle <V> (new V[]
            {
                VertexHelpers.New <V> (new Vec3(0f, height, 0f), normal),
                VertexHelpers.New <V> (new Vec3(rightOffset, 0f, 0f), normal),
                VertexHelpers.New <V> (new Vec3(leftOffset, 0f, 0f), normal)
            }));
        }
예제 #3
0
        public static Lathe <V> Turn <P> (Path <P, Vec3> path, Axis turnAxis, Vec3 offset,
                                          float stepAngle, float startAngle, float endAngle)
            where P : struct, IVertex <Vec3>
        {
            if (startAngle > endAngle)
            {
                throw new ArgumentException(
                          "Start angle must be less or equal than the end angle.If you want to turn " +
                          "the path a full circle, set the startAngle and endAngle to the same value.",
                          "startAngle");
            }
            var pathLen    = path.Vertices.Length;
            var fullCircle = startAngle == endAngle;

            if (fullCircle)
            {
                endAngle += MathHelper.TwoPi;
            }
            if (stepAngle > (endAngle - startAngle))
            {
                throw new ArgumentException(
                          "StepAngle must to be less or equal than the sweep angle (endAngle - stargAngle)",
                          "stepAngle");
            }

            var radialCount = (int)Math.Ceiling((endAngle - startAngle) / stepAngle) * 2;
            var vertices    = new V [radialCount * (pathLen - 1) * 2];
            var angle       = startAngle;
            var vertInd     = 0;
            var path1       = Positions(path, turnAxis, angle, offset);
            var firstPos    = path1;

            for (var i = 0; i < radialCount; i += 2)
            {
                angle = Math.Min(angle + stepAngle, endAngle);
                var path2 = fullCircle && i == radialCount - 2 ?
                            firstPos :
                            Positions(path, turnAxis, angle, offset);
                for (int j = 0; j < pathLen - 1; j++)
                {
                    var normal = path1[j].CalculateNormal(path2[j + 1], path1[j + 1]);
                    vertices[vertInd++] = VertexHelpers.New <V> (path1[j], normal);
                    vertices[vertInd++] = VertexHelpers.New <V> (path1[j + 1], normal);
                    vertices[vertInd++] = VertexHelpers.New <V> (path2[j + 1], normal);
                    vertices[vertInd++] = VertexHelpers.New <V> (path2[j], normal);
                }
                path1 = path2;
            }
            return(new Lathe <V> (vertices));
        }
예제 #4
0
        private static V[] GetVertices <V, P> (Path <P, Vec3> path, bool flipNormal)
            where V : struct, IVertex3D
            where P : struct, IVertex <Vec3>
        {
            var nodes  = path.Vertices;
            var pos1   = nodes[1].position;
            var pos2   = nodes[0].position;
            var pos3   = nodes.Skip(2).First(n => !pos1.AreCollinear(pos2, n.position)).position;
            var normal = pos1.CalculateNormal(pos2, pos3);

            if (flipNormal)
            {
                normal = -normal;
            }
            return(nodes.Select(n => VertexHelpers.New <V> (n.position, normal)).ToArray());
        }
예제 #5
0
        public static Quadrilateral <V> Trapezoid(float width, float height,
                                                  float topLeftOffset, float topRightOffset)
        {
            var bottomRight = width / 2f;
            var topRight    = bottomRight + topRightOffset;
            var top         = height / 2f;
            var bottomLeft  = -bottomRight;
            var topLeft     = bottomLeft + topLeftOffset;
            var bottom      = -top;
            var normal      = new Vec3(0f, 0f, 1f);

            return(new Quadrilateral <V> (new V[]
            {
                VertexHelpers.New <V> (new Vec3(topRight, top, 0f), normal),
                VertexHelpers.New <V> (new Vec3(bottomRight, bottom, 0f), normal),
                VertexHelpers.New <V> (new Vec3(bottomLeft, bottom, 0f), normal),
                VertexHelpers.New <V> (new Vec3(topLeft, top, 0f), normal)
            }));
        }
예제 #6
0
 private static V SideVertex <V> (V vertex, Vec3 normal)
     where V : struct, IVertex3D
 {
     return(VertexHelpers.New <V> (vertex.position, normal));
 }
예제 #7
0
 public static Polygon <V> FromPath <P> (Path <P, Vec3> Path)
     where P : struct, IVertex <Vec3>
 {
     return(FromVertices(Path.Vertices.Select(n => VertexHelpers.New <V> (n.position, new Vec3(0f, 0f, 1f)))));
 }
예제 #8
0
 public static Polygon <V> FromVec2s(params Vec2[] vectors)
 {
     return(FromVertices(vectors.Select(vec => VertexHelpers.New <V> (new Vec3(vec, 0f), new Vec3(0f, 0f, 1f)))));
 }