Presentation is loading. Please wait.

Presentation is loading. Please wait.

Figure 3. Converting an expression into a binary expression tree.

Similar presentations


Presentation on theme: "Figure 3. Converting an expression into a binary expression tree."— Presentation transcript:

1 Figure 3. Converting an expression into a binary expression tree.
FUNCTION PLOTTER Aarti Ragoonath • Charles Thompson • James Haralambides Abstract x ^ 2 + y * cos (x + y) We have implemented a program that produces three-dimensional plots for functions of the form z = f(x, y). The prototype utilizes library routines of the OpenGL system. Users may enter functions of two variables x and y using arithmetic operators and trigonometric functions. Operators include: addition, subtraction, multiplication, division, and the unary minus. Functions include: sine, cosine, tangent, square root, and logarithm. The user-defined functional expression is evaluated by the system in multiple stages. Initially, it is checked for syntactic errors (incorrect sequence of operands, unbalanced parentheses, unknown operands, etc.) and is trimmed of extra white spaces. The expression is later parsed and a binary expression tree is constructed. A recursive pre-order traversal of the tree is used to evaluate the expression and yield a collection of three-dimensional points (x, y, z). OpenGl controls and library functions are employed to define the three-dimensional axis system, viewpoint, bounding volume, surface characteristics, and projection method for the drawing of computed points. The system uses orthographic projection, a variation of parallel projection to provide a better visual effect. Menu options allow for rotation about the X, Y, and Z axes as well as modification of the zoom factor. Functions may be drawn in “frame” mode, where lines are used to connect three-dimensional points, or ‘fill’ mode, where surface segments are filled quadrangles. An interesting feature of the program is its capability to illustrate rotation and scaling dynamically through motion. The user may adjust rotational and scaling parameters of the function plot as it moves through three-dimensional space. The motion speed is also dynamically adjusted and a frame per second rate is displayed to measure the efficiency of the algorithm. x * y cos + ^ 2 Figure 1. Perspective vs. parallel projection. Figure 3. Converting an expression into a binary expression tree. Program Functionality Figure 2. Sample transformation matrices. Expression Evaluation Introduction The function plotter presented here targets functions of the form z = f(x, y). A function expression of the aforementioned form is initially checked for syntactic errors such as unbalanced or missing parentheses, incorrect use and order of operators and unrecognized symbols or operands. A list of implemented operators an functions includes: unary minus, addition/subtraction, multiplication/division, exponentiation, sine, cosine, tangent, inverse tangent, logarithm base 2, and square root. The program can be easily extended to include additional functions and/or operators. Following a successful parsing of the expression, it is converted into a binary expression tree. Conversion of the expression into a tree requires an iterative identification of minimum precedence operators/function and partitioning of the expression to its left and right sub-expressions. Operator/function precedence is predefined and follows the order from higher to lower precedence: function, unary minus, exponentiation, multiplication/division, and addition/subtraction. All equal operators/functions are evaluated left to right except for exponentiation. The binary tree structure is traversed using post-order traversal and evaluated to produce 3D points of the form (x, y, z). A binary expression tree is a binary tree in which: (i) Each leaf node contains a single operand. (ii)Each non-leaf node contains a single operator. (iii)The left and right sub-trees of an operator node represent sub-expressions that must be evaluated before applying the operator at the root of the sub-tree. The levels of the nodes in the tree indicate their relative precedence of evaluation. An example of an expression and its corresponding tree structure is shown in Figure 3. 3D plotting describes a graphical method that draws 3-dimensional objects on a computer screen or a similar 2-dimensional surface. Functions of 3 variables (x, y, z) are a very common example that is suitable for 3D plotting. Visualization of functions is very useful in modeling and simulation, in the study of abstract mathematical notations, and in computer-aided instruction in general. Evaluations of functional expressions result in a collection of 3D coordinates that are stored in computer memory and are projected on a plane for display purposes. Pre-computing of points is the preferred method as dynamic computation of function points is extremely intensive computationally. The points are then organized in frame or polygon structures and are projected on the plane. Mapping of 3D coordinates to a plane can be accomplished using either perspective or parallel projection. We employ orthographic projection, a special case of parallel projection. Dynamic transformation on function points includes: translation, scaling, and rotation about one of the three major axes. All such transformations, including projection, are performed using matrices. Any sequence of transformations results into a single transformation matrix thus offering higher execution speeds. Figure 1 illustrates the effects of perspective and orthographic projections. Example transformation matrices are presented in Figure 2. Figure 4. A snapshot of the program interface plotting function z = y / x. The program evaluates an expression and projects the 3D point collection on the computer screen using orthographic projection. Graphic libraries of the OpenGL interface have been used to draw points, surfaces, and apply transformations matrices. Objects are transformed from world coordinate to camera coordinate coordinates using a viewport and a viewing transformation. Important features include rotational transformations, and zooming effects. More importantly, the system is capable of motion. The plot can be rotated and scaled at variable speeds in all axes dynamically and its rotational speed is displayed in frames per second. A sample snapshot of the Graphical User Interface of the program for the function z = y / x can be seen in Figure 4.


Download ppt "Figure 3. Converting an expression into a binary expression tree."

Similar presentations


Ads by Google