Class to generate tori on a 3-sphere
コード例 #1
0
        /// <summary>
        /// Calculates a torus which divides the 3-sphere in two.
        /// </summary>
        public static Torus CreateTorus(Parameters parameters)
        {
            Torus t = new Torus();

            t.Params = parameters;
            t.InitVerts();

            // Shorter var names for inputs.
            int    n1 = parameters.NumSegments1;
            int    n2 = parameters.NumSegments2;
            double r  = parameters.Radius;
            double r1 = parameters.TubeRadius1;

            // Calc r2.
            double r2 = r - r1;

            if (r2 < 0)
            {
                r2 = 0;
            }

            r1 *= Math.Sqrt(2);
            r2 *= Math.Sqrt(2);

            double angleInc1 = 2 * Math.PI / n1;
            double angleInc2 = 2 * Math.PI / n2;

            double angle1 = 0;

            for (int i = 0; i < n1; i++)
            {
                double angle2 = 0;
                for (int j = 0; j < n2; j++)
                {
                    t.Vertices[i][j].X = r1 * Math.Cos(angle1);
                    t.Vertices[i][j].Y = r1 * Math.Sin(angle1);
                    t.Vertices[i][j].Z = r2 * Math.Cos(angle2);
                    t.Vertices[i][j].W = r2 * Math.Sin(angle2);
                    angle2            += angleInc2;
                }
                angle1 += angleInc1;
            }

            return(t);
        }
コード例 #2
0
ファイル: Torus.cs プロジェクト: roice3/Honeycombs
        /// <summary>
        /// Calculates a torus which divides the 3-sphere in two.
        /// </summary>
        public static Torus CreateTorus( Parameters parameters )
        {
            Torus t = new Torus();
            t.Params = parameters;
            t.InitVerts();

            // Shorter var names for inputs.
            int n1 = parameters.NumSegments1;
            int n2 = parameters.NumSegments2;
            double r = parameters.Radius;
            double r1 = parameters.TubeRadius1;

            // Calc r2.
            double r2 = r - r1;
            if( r2 < 0 )
                r2 = 0;

            double angleInc1 = 2 * Math.PI / n1;
            double angleInc2 = 2 * Math.PI / n2;

            double angle1 = 0;
            for( int i = 0; i < n1; i++ )
            {
                double angle2 = 0;
                for( int j = 0; j < n2; j++ )
                {
                    t.Vertices[i][j].X = r1 * Math.Cos( angle1 );
                    t.Vertices[i][j].Y = r1 * Math.Sin( angle1 );
                    t.Vertices[i][j].Z = r2 * Math.Cos( angle2 );
                    t.Vertices[i][j].W = r2 * Math.Sin( angle2 );
                    angle2 += angleInc2;
                }
                angle1 += angleInc1;
            }

            return t;
        }