Download presentation

Presentation is loading. Please wait.

Published byNikolas Rayes Modified over 3 years ago

1
Lecture 6 Data Structures & Drawing

2
Objective The objective is that you will understand: How to program the generation of 2D and 3D images. How to manipulate those images through scaling, translation, rotation and projection. How to color and shade the images. Remove hidden surfaces and create realistic lighting effects. Before any of that however, we must learn more about how to describe a drawing in terms that a computer can understand.

3
The Basic 2d data structure – Point 2d Class A point is basically two coordinates, x and y, which are “real” numbers. This suggests that we might define a Java class to represent a point. The main task that objects of the Point2d class must accomplish is to store the x and y coordinates of the point.

4
The Basic 2d data structure – Point 2d Class

6
The Basic 2d data structure – Line2d Class Lines are the basic item of drawings. Each line has two end points. This suggests that an appropriate way to describe the drawings would be in terms of two classes: Line2d and Point2d. Thus to represent L1 in this scheme, we need 3 objects:

7
The Basic 2d data structure – Line2d Class The square has the corners, we are going to refer to the corners as nodes and they have special significance for the data structure. Notice in the drawing that a line is defined between two nodes (for example line L1 connects nodes N1 and N2) but not all nodes are connected by lines (for example N1 is not connected to N3).

8
The Basic 2d data structure – Line2d Class The square has the corners, we are going to refer to the corners as nodes and they have special significance for the data structure. Notice in the drawing that a line is defined between two nodes (for example line L1 connects nodes N1 and N2) but not all nodes are connected by lines (for example N1 is not connected to N3).

9
The Basic 2d data structure – Line2d Class

10
How come there are 4 nodes on this square, but you have 8 Point2d objects - surely your duplicating data unnecessarily. Well, yes and no. You can do it using 4 points and save your self 4 objects, but that means that those lines share instances of the points and CAN NEVER BE CHANGED INDEPENDANTLY. From a data modeling point of view, the corners of the square are in fact two points that JUST HAPPEN to be in the same place.

11
The Basic 2d data structure – Line2d Class

14
The Basic 2d data structure – Shape2d Class Any shape can be described as a collection of lines. Shape2d, is a class which maintains a list of all of the lines that make up a shape. This could be implemented in many ways, in fact we shall use a Vector which we will call lines. it is useful to know how many lines make up our shape. We use and integer named numberOfLines to keep count.

15
The Basic 2d data structure – Shape2d

17
The Basic 2d data structure – Drawing2d Class A drawing can consist of many shapes - We can therefore add a final class to our data model: Drawing2d, which can maintain another list (Vector) of the various shapes.

18
The Basic 2d data structure – Drawing2d Class

19
The Basic 2d data structure – Summary So, in full, we have a drawing object, which has a list of shape objects, which have lists of line objects, which have two point objects each.

20
The Basic 2d data structure – Class Diagram Drawing2d has Many Shapes Shape2d has many Lines Line2d has tow points

21
A working Gcanvas

22
The Completed system The final class diagram of the system should look something like this.

24
Exercises Describe the following data structures: Point Line Shape Drawing Describe the complete system and the class diagram for the following drawing.

25
Exercises

Similar presentations

OK

Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.

Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on ready to serve beverages and more Ppt on hard gelatin capsule shell Ppt on airport authority of india Ppt on semiconductor diodes solar Ppt on google search engine Ppt on formal education vs self Ppt on statistics for class 11 maths Ppt on the road not taken interpretation Ppt on symbols of french revolution Ppt on water the essence of life