Chapter 6. Plotting Mathematical Expressions
In this chapter, we will create an application which will plot arbitrary mathematical expressions on a Windows Presentation Foundation (WPF)-based graphical surface. We will be using the GoF observer pattern for wiring expression input control and the rendering surface. In the process, we will develop a library which can evaluate arbitrary arithmetic expressions on the fly. The expression evaluator will support basic arithmetic operators (+
, -
, *
, /
, unary +
/-
), trigonometric functions, and a pseudo variable ($t
) which can represent the value of X-axis in a 2D Plane. During the course of this chapter, as a reader, you will learn the following:
- The observer pattern
- Parsing mathematical expressions using recursive descent
- Modeling abstract syntax tree (AST) as a composite
- The interpreter pattern
- The builder pattern
- Elementary WPF 2D graphics