mapdraw - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

mapdraw

Description:

Transforming coordinates: Is best done in a function. ... Latitude corresponds to the y direction. Longitude corresponds to the x direction. ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 27
Provided by: CU14
Category:

less

Transcript and Presenter's Notes

Title: mapdraw


1
mapdraw
  • ats315

2
Todays goal
  • Drawing a map in the graphics window!

3
Previous Skills
  • Basic graphic commands (opening windows, drawing
    lines)
  • Reading files
  • The while statement
  • functions

4
The Map Files
  • state.ats315.dat
  • nice state outlines
  • usa_cnty.ats315.dat
  • nice county outlines
  • rd_int.ats315.dat
  • U.S. Interstate Highways
  • rivermap.ats315.dat
  • major U.S. rivers

5
Where are the map files?
  • /usr/local/wxp/etc/

6
How the map files work
  • They are collections of line segments.
  • lat1 lon1 lat2 lon2
  • You dont know in advance how many line segments
    there will be.

7
Reading the map file
while (!feof(fmap)) fscanf (fmap, f f f
f,lat1, lon1, lat2, lon2) / Now do stuff
with this information /
8
Reading the map file
while (!feof(fmap)) fscanf (fmap, f f f
f,lat1, lon1, lat2, lon2) / Now do stuff
with this information /
  • What to do with these lats and lons is the tricky
    part!

9
Why this is tricky
  • The map file is full of latitudes and longitudes
    of the line segments that make up the map.
  • Your graphics window is NOT expressed in terms of
    latitude and longituderather it is a unit
    square!
  • Therefore, you need to transform (lat,lon) into
    (x,y).

10
Transforming coordinates
  • Is best done in a function.
  • Can be done in two functions, but Id prefer to
    see you do it with just one.

11
Transformations
  • Latitude corresponds to the y direction.
  • Longitude corresponds to the x direction.

12
Transformations
  • Lets focus on LATITUDE first.

13
Transformations
  • You need some kind of function that converts the
    latitude to a number between 0 and 1.

14
Transformations
  • More to the point, you need this function to
    convert JUST THE PART OF THE MAP YOU WANT to a
    number between 0 and 1.

15
Transformations
  • For example, here clearly some latitudes are
    outside the (0,1) range for y, and so they arent
    plotted.

16
Transformations
  • You could write a function called
    transformlatitude(lat).

17
Transformations
  • Your northernmost latitude becomes 1.
  • YOU get to pick your northernmost latitude!

18
Transformations
  • Your southernmost latitude becomes 0.
  • YOU get to pick your southernmost latitude!

19
Transformations
  • Could look something like this

float transformlatitude(float lat) float
northernmost, southernmost. y northernmost
40. southernmost 30. y (lat
southernmost) / (northernmost
southernmost) return y
20
Transformations
  • Interpolates your lat between 0 and 1 if it is
    between northernmost and southernmost

float transformlatitude(float lat) float
northernmost, southernmost. y northernmost
40. southernmost 30. y (lat
southernmost) / (northernmost
southernmost) return y
21
Transformations
  • Then your map reading program could call
    transformlatitude to get a value on the unit
    square

while (!feof(fmap)) fscanf (fmap, f f f
f,lat1, lon1, lat2, lon2) y1
transformlatitude (lat1) y2 transformlatitude
(lat2) / Now do this with the longitudes as
well! / / Now do stuff with this information
/
22
Transformations
  • A similar function could be written for
    longitudes then

while (!feof(fmap)) fscanf (fmap, f f f
f,lat1, lon1, lat2, lon2) y1
transformlatitude (lat1) y2 transformlatitude
(lat2) x1 transformlongitude (lon1) x2
transformlongitude (lon2) / Now do stuff with
this information /
23
Transformations
  • Then decide what you are going to do with this
    new (x1,y1) and (x2,y2)!

while (!feof(fmap)) fscanf (fmap, f f f
f,lat1, lon1, lat2, lon2) y1
transformlatitude (lat1) y2 transformlatitude
(lat2) x1 transformlongitude (lon1) x2
transformlongitude (lon2) / Now do stuff with
this information /
24
Ideally
  • you really should use just ONE function to
    transform the latitudes and longitudes into x and
    y
  • transform(lat,lon,x,y)
  • But, to do this, youll need to think VERY
    carefully about which parameters are passed by
    VALUE and which are passed by ADDRESS!

25
Which one is it?
  • transform(lat,lon,x,y)
  • transform(lat,lon,x,y)
  • transform(lat,lon,x,y)
  • transform(lat,lon,x,y)
  • Or even something else????

26
Your Assignment
  • There is no specific assignment about this
    lecture.
  • You DO have to draw a mapwith clippingfor
    Friday.
  • Therefore, start working on this NOW!
Write a Comment
User Comments (0)
About PowerShow.com