Exemple #1
0
        public Cone( double radius, double height )
        {
            IExpression fx = new MultExpression(
                                    new MultExpression(
                                        new SubExpression(
                                            new ConstantExpression( height ),
                                            new VariableExpression( "v" ) ),
                                        new ConstantExpression( radius/height ) ),
                                    new CosineExpression(
                                        new VariableExpression( "u" ) ) );
            IExpression fy = new VariableExpression( "v" );
            IExpression fz = new MultExpression(
                                    new MultExpression(
                                        new SubExpression(
                                            new ConstantExpression( height ),
                                            new VariableExpression( "v" ) ),
                                        new ConstantExpression( radius/height ) ),
                                    new SineExpression(
                                        new NegateExpression(
                                            new VariableExpression( "u" ) ) ) );

            Init( fx, fy, fz, -Math.PI, Math.PI, 0.0, height );
        }
        public Cone(double radius, double height)
        {
            IExpression fx = new MultExpression(
                new MultExpression(
                    new SubExpression(
                        new ConstantExpression(height),
                        new VariableExpression("v")),
                    new ConstantExpression(radius / height)),
                new CosineExpression(
                    new VariableExpression("u")));
            IExpression fy = new VariableExpression("v");
            IExpression fz = new MultExpression(
                new MultExpression(
                    new SubExpression(
                        new ConstantExpression(height),
                        new VariableExpression("v")),
                    new ConstantExpression(radius / height)),
                new SineExpression(
                    new NegateExpression(
                        new VariableExpression("u"))));

            Init(fx, fy, fz, -Math.PI, Math.PI, 0.0, height);
        }
Exemple #3
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        private static IExpression ParseFactor()
        {
            IExpression exp = null;
            do
            {
                IExpression right = null;
                switch ( CurrentToken.type )
                {
                case TokenType.Variable:
                    right = new VariableExpression( CurrentToken.value );
                    Eat( TokenType.Variable );
                    break;

                case TokenType.Sine:
                case TokenType.Cosine:
                case TokenType.Tangent:
                    right = ParseFunction();
                    break;

                case TokenType.OpenParen:
                    Eat( TokenType.OpenParen );
                    right = ParseAddExpression();
                    Eat( TokenType.CloseParen );
                    break;

                default:
                    throw new UnexpectedBehaviorException( "Unexpected token in Factor: " + CurrentToken.type );
                }

                exp = ( exp == null ) ? right : new MultExpression( exp, right );

            } while ( Check( FirstFactor ) );

            return exp;
        }
        /// <summary>
        /// Creates a mesh with a horizontal and vertical resolution indicated
        /// by the input parameters.  It will generate
        /// (precisionU-1)*(precisionV-1) quads.
        /// </summary>
        public Model3DGroup CreateWireframeModel(int precisionU, int precisionV)
        {
            lengthX = precisionU;
            lengthY = precisionV;
            du      = (uMax - uMin) / (double)(precisionU - 1);
            dv      = (vMax - vMin) / (double)(precisionV - 1);

            positions = new Point3D[lengthX, lengthY];

            double v = vMin;

            for (int y = 0; y < lengthY; y++)
            {
                double u = uMin;
                if (y == lengthY - 1)
                {
                    v = vMax;
                }
                for (int x = 0; x < lengthX; x++)
                {
                    if (x == lengthX - 1)
                    {
                        u = uMax;
                    }
                    VariableExpression.Define("u", u);
                    VariableExpression.Define("v", v);
                    positions[x, y] = Evaluate();
                    u += du;
                }
                v += dv;
            }
            VariableExpression.Undefine("u");
            VariableExpression.Undefine("v");

            Model3DGroup group = new Model3DGroup();

            // TODO: Remove
            //ScreenSpaceLines3D lines;

            /*
             * // Create Horizontal lines
             * for ( int y = 0; y < lengthY; y++ )
             * {
             *  lines = new ScreenSpaceLines3D();
             *  lines.Color = Colors.Black;
             *  lines.Thickness = 1;
             *  for ( int x = 0; x < lengthX; x++ )
             *  {
             *      lines.Points.Add( positions[ x,y ] );
             *  }
             *  group.Children.Add( lines );
             * }
             *
             * // Create Vertical lines
             * for ( int x = 0; x < lengthX; x++ )
             * {
             *  lines = new ScreenSpaceLines3D();
             *  lines.Color = Colors.Black;
             *  lines.Thickness = 1;
             *  for ( int y = 0; y < lengthY; y++ )
             *  {
             *      lines.Points.Add( positions[ x,y ] );
             *  }
             *  group.Children.Add( lines );
             * }
             */

            return(group);
        }