Presentation is loading. Please wait.

Presentation is loading. Please wait.

Contouring in C ATS 315. How Contours Really Work Contours may LOOK like curves, but they are really just straight line segments.

Similar presentations


Presentation on theme: "Contouring in C ATS 315. How Contours Really Work Contours may LOOK like curves, but they are really just straight line segments."— Presentation transcript:

1 Contouring in C ATS 315

2 How Contours Really Work Contours may LOOK like curves, but they are really just straight line segments.

3

4

5 How Contouring Works:

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29 So What We Are Really Worried About…

30

31

32 The northwest corner is grid[i][j]. grid[i][j]

33 The northwest corner is grid[i][j]. grid[i][j]grid[i][j+1] grid[i+1][j]grid[i+1][j+1]

34 The northwest corner is grid[i][j]. grid[i][j]grid[i][j+1] grid[i+1][j]grid[i+1][j+1]

35 How the contour is drawn depends on the value of the contour and the values at the four corners! grid[i][j]grid[i][j+1] grid[i+1][j]grid[i+1][j+1]

36 For simplicity, rename the values at the corners: nwne swse

37 Count the number of corners with values greater than the contour line. nwne swse

38 CornersGreaterThanContour can be 0, 1, 2, 3, or 4. nwne swse

39 if (CornersGreaterThanContour==0) do nothing nwne swse

40 if (CornersGreaterThanContour==4) do nothing nwne swse

41 if (CornersGreaterThanContour==1)… there are four possibilities: nwne swse

42 if (CornersGreaterThanContour==1)… there are four possibilities: nwne swse Possibility 1: Only the northwest corner is greater than the value of the contour.

43 if (CornersGreaterThanContour==1)… there are four possibilities: nwne swse Possibility 2: Only the northeast corner is greater than the value of the contour.

44 if (CornersGreaterThanContour==1)… there are four possibilities: nwne swse Possibility 3: Only the southeast corner is greater than the value of the contour.

45 if (CornersGreaterThanContour==1)… there are four possibilities: nwne swse Possibility 4: Only the southwest corner is greater than the value of the contour.

46 if (CornersGreaterThanContour==2)… there are three possibilities: nwne swse

47 if (CornersGreaterThanContour==2)… there are three possibilities: nwne swse Possibility 1: The line should be drawn from the west edge to the east edge. Either: Both ne and nw are bigger than contour… or Both ne and nw are smaller than contour.

48 if (CornersGreaterThanContour==2)… there are three possibilities: nwne swse Possibility 2: The line should be drawn from the north edge to the south edge. Either: Both ne and se are bigger than contour… or Both ne and se are smaller than contour.

49 if (CornersGreaterThanContour==2)… there are three possibilities: nwne swse Possibility 3: Two contour lines pass through this box. Either: Both nw and se are bigger than contour… or Both nw and se are smaller than contour.

50 if (CornersGreaterThanContour==3)… there are four possibilities: nwne swse

51 if (CornersGreaterThanContour==3)… there are four possibilities: nwne swse Possibility 1: Only the northwest corner is less than the value of the contour.

52 if (CornersGreaterThanContour==3)… there are four possibilities: nwne swse Possibility 2: Only the northeast corner is less than the value of the contour.

53 if (CornersGreaterThanContour==3)… there are four possibilities: nwne swse Possibility 3: Only the southeast corner is less than the value of the contour.

54 if (CornersGreaterThanContour==3)… there are four possibilities: nwne swse Possibility 4: Only the southwest corner is less than the value of the contour.

55 What will this program look like?

56 /* Compute CornersGreaterThanContour */ if (CornersGreaterThanContour == 0) { } if (CornersGreaterThanContour == 1) { } if (CornersGreaterThanContour == 2) { } if (CornersGreaterThanContour == 3) { } if (CornersGreaterThanContour == 4) { }

57 What will this program look like? /* Compute CornersGreaterThanContour */ if (CornersGreaterThanContour == 0) { /* Do nothing */ } if (CornersGreaterThanContour == 1) { } if (CornersGreaterThanContour == 2) { } if (CornersGreaterThanContour == 3) { } if (CornersGreaterThanContour == 4) { /* Do nothing */ }

58 What will this program look like? if (CornersGreaterThanContour == 1) { } if (CornersGreaterThanContour == 2) { } if (CornersGreaterThanContour == 3) { }

59 What will this program look like? if (CornersGreaterThanContour == 1) { if( nw > contour) { } if( ne > contour) { } if( se > contour) { } if( sw > contour) { } } if (CornersGreaterThanContour == 2) { } if (CornersGreaterThanContour == 3) { }

60 What will this program look like? if (CornersGreaterThanContour == 2) { } if (CornersGreaterThanContour == 3) { }

61 What will this program look like? if (CornersGreaterThanContour == 2) { if((ne > contour && nw > contour) || (ne < contour && nw < contour)) { } if((ne > contour && se > contour) || (ne < contour && se < contour)) { } if((nw > contour && se > contour) || (nw < contour && se < contour)) { } } if (CornersGreaterThanContour == 3) { }

62 What will this program look like? if (CornersGreaterThanContour == 3) { }

63 What will this program look like? if (CornersGreaterThanContour == 3) { if( nw < contour) { } if( ne < contour) { } if( se < contour) { } if( sw < contour) { } }

64 Deciding how to draw the contour nwne swse Let’s say that you have determined that this is the kind of line you need to draw. This line segment has a starting point and an ending point.

65 Deciding how to draw the contour nwne swse What determines the location of the starting point?

66 Deciding how to draw the contour nwne swse What determines the location of the starting point? INTERPOLATION!

67 Deciding how to draw the contour nwne swse Suppose we are drawing the 1000 mb contour. nw = 999.9 ne = 1022.1

68 Deciding how to draw the contour nwne swse Suppose we are drawing the 1000 mb contour. nw = 982.2 ne = 1001.1

69 Deciding how to draw the contour nwne swse startlat = ??? startlon = ???

70 Deciding how to draw the contour nwne swse startlat = depends on: latitude of nw latitude of ne value at nw value at ne value of contour startlon = depends on: longitude of nw longitude of ne value at nw value at ne value of contour

71 Deciding how to draw the contour nwne swse interp(gridlatitude[i][j], &startlat, gridlatitude[i][j+1], nw, contour, ne); interp(gridlongitude[i][j], &startlon, gridlongitude[i][j+1], nw, contour, ne);

72 Deciding how to draw the contour nwne swse How about the endlat and endlon?

73 Deciding how to draw the contour nwne swse interp(gridlatitude[i][j+1], &endlat, gridlatitude[i+1][j+1], ne, contour, se); interp(gridlongitude[i][j+1], &endlon, gridlongitude[i+1][j+1], ne, contour, se);

74 Deciding how to draw the contour nwne swse Once you have (startlat, startlon) and (endlat, endlon): 1.tranform 2.clip 3.gline

75 How this produces contours

76

77 i=0 i=1 i=2 i=3 j=0j=1j=2j=3

78 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

79 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

80 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

81 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

82 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

83 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

84 How this produces contours i=0 i=1 i=2 i=3 j=0j=1j=2j=3

85 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

86 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

87 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

88 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

89 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

90 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

91 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

92 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

93 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

94 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

95 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

96 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

97 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

98 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

99 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

100 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

101 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

102 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

103 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

104 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

105 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

106 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

107 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

108 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

109 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

110 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

111 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

112 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

113 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

114 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

115 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

116 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

117 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

118 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

119 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

120 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

121 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

122 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

123 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

124 for(contour=mincontour;contour<=maxcontour;contour=contour+conint) i=0 i=1 i=2 i=3 j=0j=1j=2j=3

125 Great, I can picture what this looks like, but how do I do it?

126 The Steps Open the window Draw the base map Read the sao.cty file Read the current_sao.wxp file Produce grids of objectively analyzed data. Contour (like this….)

127 for(i=0;i<NUMROWS-1;i++) { for(j=0;j<NUMCOLS-1;j++) { for(contour=mincon;contour<=maxcon; contour=contour+conint) { CornersGreaterThanContour = ?????; if (CornersGreaterThanContour==0) { } if (CornersGreaterThanContour==1) { } if (CornersGreaterThanContour==2) { } if (CornersGreaterThanContour==3) { } if (CornersGreaterThanContour==4) { } }

128 for(i=0;i<NUMROWS-1;i++) { for(j=0;j<NUMCOLS-1;j++) { for(contour=mincon;contour<=maxcon; contour=contour+conint) { CornersGreaterThanContour = ?????; if (CornersGreaterThanContour==0) { } if (CornersGreaterThanContour==1) { } if (CornersGreaterThanContour==2) { } if (CornersGreaterThanContour==3) { } if (CornersGreaterThanContour==4) { } } For every “square” on the map… (Notice that there are (NUMROWS-1)x(NUMCOLS-1) squares…)

129 for(i=0;i<NUMROWS-1;i++) { for(j=0;j<NUMCOLS-1;j++) { for(contour=mincon;contour<=maxcon; contour=contour+conint) { CornersGreaterThanContour = ?????; if (CornersGreaterThanContour==0) { } if (CornersGreaterThanContour==1) { } if (CornersGreaterThanContour==2) { } if (CornersGreaterThanContour==3) { } if (CornersGreaterThanContour==4) { } } For every possible contour level… (We’ll discuss how to figure this out shortly.)

130 for(i=0;i<NUMROWS-1;i++) { for(j=0;j<NUMCOLS-1;j++) { for(contour=mincon;contour<=maxcon; contour=contour+conint) { CornersGreaterThanContour = ?????; if (CornersGreaterThanContour==0) { } if (CornersGreaterThanContour==1) { } if (CornersGreaterThanContour==2) { } if (CornersGreaterThanContour==3) { } if (CornersGreaterThanContour==4) { } } Determine the number of corners on this square that are greater than the current contour level. (This will take about 5 lines of code.)

131 for(i=0;i<NUMROWS-1;i++) { for(j=0;j<NUMCOLS-1;j++) { for(contour=mincon;contour<=maxcon; contour=contour+conint) { CornersGreaterThanContour = ?????; if (CornersGreaterThanContour==0) { } if (CornersGreaterThanContour==1) { } if (CornersGreaterThanContour==2) { } if (CornersGreaterThanContour==3) { } if (CornersGreaterThanContour==4) { } } For each of the 5 possible values of CornersGreaterThanContour, you’ll need the elaborate “if” statements discussed earlier.

132 for(i=0;i<NUMROWS-1;i++) { for(j=0;j<NUMCOLS-1;j++) { for(contour=mincon;contour<=maxcon; contour=contour+conint) { CornersGreaterThanContour = ?????; if (CornersGreaterThanContour==0) { } if (CornersGreaterThanContour==1) { } if (CornersGreaterThanContour==2) { } if (CornersGreaterThanContour==3) { } if (CornersGreaterThanContour==4) { } } Where do you get these values? mincon, maxcon, conint

133 You could just prompt the user for these three values. Better: prompt the user for conint, and compute mincon and maxcon! But, to do this, you first need to be able to compute max and min of the grid!

134 max and min Suppose you have a 2D grid of floating point numbers. min needs to be the lowest value in the grid, and max needs to be the highest. 22.525.528.3 21.515.529.0 29.118.219.9

135 max and min min = 100000000.; max = -100000000.; for(i=0;i<NUMROWS;i++) { for(j=0;j<NUMCOLS;j++) { if (grid[i][j] < min) min = grid[i][j]; if (grid[i][j] > max) max = grid[i][j]; } 22.525.528.3 21.515.529.0 29.118.219.9

136 max and min min = 100000000.; max = -100000000.; for(i=0;i<NUMROWS;i++) { for(j=0;j<NUMCOLS;j++) { if (grid[i][j] < min) min = grid[i][j]; if (grid[i][j] > max) max = grid[i][j]; } Set min to a very high number and max to a very low number. 22.525.528.3 21.515.529.0 29.118.219.9

137 max and min min = 100000000.; max = -100000000.; for(i=0;i<NUMROWS;i++) { for(j=0;j<NUMCOLS;j++) { if (grid[i][j] < min) min = grid[i][j]; if (grid[i][j] > max) max = grid[i][j; } For every element of the 2D array… 22.525.528.3 21.515.529.0 29.118.219.9

138 max and min min = 100000000.; max = -100000000.; for(i=0;i<NUMROWS;i++) { for(j=0;j<NUMCOLS;j++) { if (grid[i][j] < min) min = grid[i][j]; if (grid[i][j] > max) max = grid[i][j]; } If grid[i][j] < min, min=grid[i][j] ! 22.525.528.3 21.515.529.0 29.118.219.9

139 max and min min = 100000000.; max = -100000000.; for(i=0;i<NUMROWS;i++) { for(j=0;j<NUMCOLS;j++) { if (grid[i][j] < min) min = grid[i][j]; if (grid[i][j] > max) max = grid[i][j]; } If grid[i][j] > max, max=grid[i][j] ! 22.525.528.3 21.515.529.0 29.118.219.9

140 But Sadly… min  mincon max  maxcon

141 But Happily… mincon = (float) (( (int)(min/conint) + 1) * conint) maxcon = (float) (( (int)(max/conint) ) * conint) You can work out the math and see that this works! (maxcon is easier than mincon)

142 Grading Assignment 15 Properly determine mincon and maxcon from a grid of data, prompting the user for the contour interval.

143 Grading Assignment 15 Correctly determining most of the things you need to draw contours, but not getting good output:

144 Grading Assignment 15 Successfully contouring temperature fields:

145 Grading Assignment 15 Successfully contouring any grid of data chosen by the user:

146 Suggested “Impressive” Things Variable domains Variable colors for the contours Nice labels for the plot (NOT contour labels!)


Download ppt "Contouring in C ATS 315. How Contours Really Work Contours may LOOK like curves, but they are really just straight line segments."

Similar presentations


Ads by Google