Book contents
- Frontmatter
- Contents
- Preface
- I Why Z?
- II Introducing Z
- III Elements of Z
- IV Studies in Z
- 16 Document control system
- 17 Text processing
- 18 Eight queens
- 19 Computer graphics and computational geometry
- 20 Rule-based programming
- 21 Graphical user interface
- 22 Safety-critical protection system
- 23 Modelling large systems
- 24 Object-oriented programming
- 25 Concurrency and real time
- Further reading
- V Programming with Z
- Further reading
- A Glossary of Z notation
- B Omitted features
- C Operator precedence
- D The Z mathematical tool-kit
- E Selected Laws
- F Solutions to selected exercises
- G Other formal notations
- Bibliography
- Index
19 - Computer graphics and computational geometry
Published online by Cambridge University Press: 06 July 2010
- Frontmatter
- Contents
- Preface
- I Why Z?
- II Introducing Z
- III Elements of Z
- IV Studies in Z
- 16 Document control system
- 17 Text processing
- 18 Eight queens
- 19 Computer graphics and computational geometry
- 20 Rule-based programming
- 21 Graphical user interface
- 22 Safety-critical protection system
- 23 Modelling large systems
- 24 Object-oriented programming
- 25 Concurrency and real time
- Further reading
- V Programming with Z
- Further reading
- A Glossary of Z notation
- B Omitted features
- C Operator precedence
- D The Z mathematical tool-kit
- E Selected Laws
- F Solutions to selected exercises
- G Other formal notations
- Bibliography
- Index
Summary
Z can describe data structures. In this chapter we'll use Z to define the fundamental objects of computer graphics and computational geometry: points, line segments, contours, and polygons.
Consider the distinction between a contour, which is any sequence of connected line segments, and a polygon, which is a closed contour that has an inside and an outside (Figure 19.1). Your eye can see the difference immediately, and the distinction is vital for many computations of great practical importance.
Figure 19.2 is a computer graphic that shows a view of a patient's anatomy and radiation beam geometry, used to plan this patient's radiation treatment for cancer. Cross-sections of anatomical structures must be polygons, not just contours, and the physics calculations that compute the radiation dose depend on this. If some contours are not closed, or cross over themselves, the dose calculations may be incorrect.
The difference between contours and polygons is vital, but there is no way to express this distinction in most programming languages: You have to represent both as mere sequences (arrays or lists) of points. Data types in programming languages correspond closely to the way data are represented in computer memory: If two objects are stored in the same format, they belong to the same data type. Z is far more expressive because we can distinguish data types based on their values and constraints between the values of their components. This enables us to define data types that capture such requirements as “a closed contour that doesn't cross over itself.”
- Type
- Chapter
- Information
- The Way of ZPractical Programming with Formal Methods, pp. 180 - 188Publisher: Cambridge University PressPrint publication year: 1996