Пример #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);
        }
Пример #2
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);
        }
Пример #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) / (precisionU - 1);
            _dv      = (VMax - VMin) / (precisionV - 1);

            _positions = new Point3D[_lengthX, _lengthY];

            var v = VMin;

            for (var y = 0; y < _lengthY; y++)
            {
                var u = UMin;
                if (y == _lengthY - 1)
                {
                    v = VMax;
                }
                for (var 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");

            var 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);
        }