コード例 #1
0
ファイル: Vector.cs プロジェクト: radumg/DesignScriptStudio
 public static Vector ByCoordinates(CoordinateSystem coordinateSystem, double x, double y, double z)
 {
     if (coordinateSystem == null)
     {
         throw new System.ArgumentNullException("coordinateSystem");
     }
     using (var p = Point.ByCartesianCoordinates(coordinateSystem, x, y, z))
     {
         Vector vec = coordinateSystem.Origin.DirectionTo(p);
         vec.ContextCoordinateSystem = coordinateSystem;
         return(vec);
     }
 }
コード例 #2
0
ファイル: Utilities.cs プロジェクト: scottmitchell/DynaShape
        public static Dictionary <string, object> PlaneMesh(
            [DefaultArgument("CoordinateSystem.ByOriginVectors(Point.Origin(), Vector.XAxis(), Vector.YAxis())")] CoordinateSystem cs,
            [DefaultArgument("20.0")] double lengthX,
            [DefaultArgument("20.0")] double lengthY,
            [DefaultArgument("20")] int divX,
            [DefaultArgument("20")] int divY,
            [DefaultArgument("true")] bool alternatingDiagons)
        {
            if (divX < 1 || divY < 0)
            {
                throw new Exception("divX and divY must be larger than 0");
            }

            List <Point>      vertices           = new List <Point>((divX + 1) * (divY + 1));
            Vector2Collection textureCoordinates = new Vector2Collection();

            for (int j = 0; j <= divY; j++)
            {
                for (int i = 0; i <= divX; i++)
                {
                    vertices.Add(
                        Point.ByCartesianCoordinates(
                            cs,
                            ((double)i / divX - 0.5f) * lengthX,
                            ((double)j / divY - 0.5f) * lengthY));

                    textureCoordinates.Add(new Vector2((float)i / (float)(divX), 1f - (float)j / (float)(divY)));
                }
            }

            List <int>         indices = new List <int>();
            List <List <int> > quadFaceVertexIndices = new List <List <int> >();

            for (int j = 0; j < divY; j++)
            {
                for (int i = 0; i < divX; i++)
                {
                    int a = i + j * (divX + 1);
                    int b = i + 1 + j * (divX + 1);
                    int c = i + 1 + (j + 1) * (divX + 1);
                    int d = i + (j + 1) * (divX + 1);

                    quadFaceVertexIndices.Add(new List <int> {
                        a, b, c, d
                    });

                    if (alternatingDiagons)
                    {
                        if ((i + j) % 2 == 0)
                        {
                            indices.Add(a);
                            indices.Add(b);
                            indices.Add(c);
                            indices.Add(a);
                            indices.Add(c);
                            indices.Add(d);
                        }
                        else
                        {
                            indices.Add(a);
                            indices.Add(b);
                            indices.Add(d);
                            indices.Add(b);
                            indices.Add(c);
                            indices.Add(d);
                        }
                    }
                    else
                    {
                        indices.Add(a);
                        indices.Add(b);
                        indices.Add(c);
                        indices.Add(a);
                        indices.Add(c);
                        indices.Add(d);
                    }
                }
            }

            return(new Dictionary <string, object>()
            {
                { "mesh", Mesh.ByVerticesAndIndices(vertices, indices) },
                { "quadFaceVertexIndices", quadFaceVertexIndices },
                { "textureCoordinates", new TextureCoordinateSet(textureCoordinates) },
            });
        }
コード例 #3
0
ファイル: Utilities.cs プロジェクト: scottmitchell/DynaShape
        public static Dictionary <string, object> RectangularGrid(
            [DefaultArgument("CoordinateSystem.ByOriginVectors(Point.Origin(), Vector.XAxis(), Vector.YAxis())")] CoordinateSystem cs,
            [DefaultArgument("20.0")] double lengthX,
            [DefaultArgument("20.0")] double lengthY,
            [DefaultArgument("20")] int divX,
            [DefaultArgument("20")] int divY)
        {
            if (divX < 1 || divY < 0)
            {
                throw new Exception("divX and divY must be larger than 0");
            }

            List <Point> all = new List <Point>((divX + 1) * (divY + 1));

            for (int j = 0; j <= divY; j++)
            {
                for (int i = 0; i <= divX; i++)
                {
                    all.Add(
                        Point.ByCartesianCoordinates(
                            cs,
                            ((double)i / divX - 0.5f) * lengthX,
                            ((double)j / divY - 0.5f) * lengthY));
                }
            }

            List <List <Point> > xRows = new List <List <Point> >();

            for (int j = 0; j <= divY; j++)
            {
                List <Point> xRow = new List <Point>();
                for (int i = 0; i <= divX; i++)
                {
                    xRow.Add(all[i + j * (divX + 1)]);
                }
                xRows.Add(xRow);
            }

            List <List <Point> > yRows = new List <List <Point> >();

            for (int i = 0; i <= divX; i++)
            {
                List <Point> yRow = new List <Point>();
                for (int j = 0; j <= divY; j++)
                {
                    yRow.Add(all[i + j * (divX + 1)]);
                }
                yRows.Add(yRow);
            }

            List <List <Point> > quads = new List <List <Point> >();

            for (int j = 0; j < divY; j++)
            {
                for (int i = 0; i < divX; i++)
                {
                    quads.Add(
                        new List <Point> {
                        all[i + j * (divX + 1)],
                        all[i + 1 + j * (divX + 1)],
                        all[i + 1 + (j + 1) * (divX + 1)],
                        all[i + (j + 1) * (divX + 1)]
                    });
                }
            }

            return(new Dictionary <string, object> {
                { "all", all },
                { "xRows", xRows },
                { "yRows", yRows },
                { "borders", new List <List <Point> > {
                      xRows[0], yRows[divX], xRows[divY], yRows[0]
                  } },
                { "corners", new List <Point> {
                      all[0], all[divX], all[(divX + 1) * (divY + 1) - 1], all[(divX + 1) * divY]
                  } },
                { "quads", quads }
            });
        }