예제 #1
0
        public static CrossSectionOfLine GetStarShapedPolygon(double innerRadius, double outerRadius, int starArms)
        {
            var result = new CrossSectionOfLine();

            int numVertices = starArms * 2;
            int numNormals  = 2 * numVertices;

            result._vertices      = new PointD2D[numVertices];
            result._isVertexSharp = new bool[numVertices];
            result._normals       = new VectorD2D[numNormals];

            for (int i = 0; i < numVertices; ++i)
            {
                double phi    = (Math.PI * (2 * i)) / numVertices;
                double radius = 0 == (i % 2) ? outerRadius : innerRadius;
                result._vertices[i]      = new PointD2D(radius * Math.Cos(phi), radius * Math.Sin(phi));
                result._isVertexSharp[i] = true;
            }

            // now the normals, we calculate them using the cross product with the z-axis
            var zaxis = new VectorD3D(0, 0, 1);

            for (int i = 0; i < numVertices; ++i)
            {
                var       line  = (VectorD2D)(result._vertices[(i + 1) % numVertices] - result._vertices[i]);
                VectorD2D cross = new VectorD2D(line.Y, line.X).Normalized;
                result._normals[(2 * i + 1) % numNormals] = cross;
                result._normals[(2 * i + 2) % numNormals] = cross;
            }

            // normals
            return(result);
        }
예제 #2
0
        public static CrossSectionOfLine GetSquareCrossSection(double width, double height)
        {
            var    result = new CrossSectionOfLine();
            double w2     = width / 2;
            double h2     = height / 2;

            result._vertices      = new PointD2D[4];
            result._isVertexSharp = new bool[4];
            result._normals       = new VectorD2D[8];

            result._vertices[0] = new PointD2D(w2, -h2);
            result._vertices[1] = new PointD2D(w2, h2);
            result._vertices[2] = new PointD2D(-w2, h2);
            result._vertices[3] = new PointD2D(-w2, -h2);

            result._isVertexSharp[0] = true;
            result._isVertexSharp[1] = true;
            result._isVertexSharp[2] = true;
            result._isVertexSharp[3] = true;

            result._normals[0] = new VectorD2D(0, -1);
            result._normals[1] = new VectorD2D(1, 0);
            result._normals[2] = new VectorD2D(1, 0);
            result._normals[3] = new VectorD2D(0, 1);
            result._normals[4] = new VectorD2D(0, 1);
            result._normals[5] = new VectorD2D(-1, 0);
            result._normals[6] = new VectorD2D(-1, 0);
            result._normals[7] = new VectorD2D(0, -1);

            return(result);
        }
예제 #3
0
        public static CrossSectionOfLine GetRegularRoundedPolygon(double radius, int edges)
        {
            var result = new CrossSectionOfLine
            {
                _vertices      = new PointD2D[edges],
                _isVertexSharp = new bool[edges],
                _normals       = new VectorD2D[edges]
            };

            for (int i = 0; i < edges; ++i)
            {
                double phi = (2 * Math.PI * i) / edges;
                result._vertices[i]      = new PointD2D(radius * Math.Cos(phi), radius * Math.Sin(phi));
                result._isVertexSharp[i] = false;
                result._normals[i]       = new VectorD2D(Math.Cos(phi), Math.Sin(phi));
            }

            // normals
            return(result);
        }
예제 #4
0
        public static CrossSectionOfLine GetRegularSharpPolygon(double radius, int edges)
        {
            var result = new CrossSectionOfLine
            {
                _vertices      = new PointD2D[edges],
                _isVertexSharp = new bool[edges],
                _normals       = new VectorD2D[2 * edges]
            };

            for (int i = 0; i < edges; ++i)
            {
                double phi = (Math.PI * (2 * i)) / edges;
                result._vertices[i]      = new PointD2D(radius * Math.Cos(phi), radius * Math.Sin(phi));
                result._isVertexSharp[i] = true;
                double phim = (Math.PI * (2 * i - 1)) / edges;
                result._normals[2 * i] = new VectorD2D(Math.Cos(phim), Math.Sin(phim));
                double phip = (Math.PI * (2 * i + 1)) / edges;
                result._normals[2 * i + 1] = new VectorD2D(Math.Cos(phip), Math.Sin(phip));
            }

            // normals
            return(result);
        }