For the first deliverable, you will implement the building blocks for our term project. The main goal at this stage is to create the infrastructure that will support the larger scope of an urban traffic simulator described in the project overview. For now, that means you need to write code that creates, updates, and animates a single vehicle on a road-segment. As a graphical application, you will be using some of the same concepts you have encountered in earlier exercises using the (HtDP/2e) image and universe teachpacks. Make sure you create and then utilize global constants for things such as the width and height of your world so that they can be changed easily later.
What are the properties of an automobile that we would want to model if we want it to move about? To start with, we might represent the location, direction, and speed. Since we want to display an animation, we could also associate an image with a vehicle. Road segments would natually have a start and an end point (thinking of them as one-way segments). Anticipating that we will have more than one road segment in an urban road network, we might also want to provide a field for vehicles to store the particular road-segment on which it is currently traveling. Although development in subsequent deliverables may cause us to add or subtract features of vehicles and/or roadsegments, these will allow us to get started.
For the first project deliverable, you should use the structure definition: (define-struct vehicle (loc speed road img)) and its corresponding data definition: a vehicle is a structure: (make-vehicle p n rs i), where p is a posn representing the car's location, n is a number representing its speed, rs is a roadsegment on which the car is traveling, and i is the car's image.
The roadsegment structure definiton is as follows: (define-struct roadsegment (start end)), with its associated data-definition: a roadsegment (RS) is a structure: (make-roadsegment p1 p2), where p1 and p2 are both posns. Note that road segments can stretch between two arbitrary points, and the vehicles must travel on them accordingly. Be sure to write your code in a general way to support this requirement.
First, you will want a collection of utilities. Since we will mainly be using posns to represent both locations and directions for the various operations on vehicles that we will be performing, you should create a number of utility functions that operate on posns. I will prescribe some utilities but you should write additional functions as you have use for them. Minimally, you will want functions that add and subtract two posns, scales a posn by a factor, and finds the magnitude of a posn.
To display a single vehicle, you should either locate and insert an overhead image of a car or create an image with the shape primitives in the image teachpack. The image will need to be rotated to the appropriate orientation of the roadsegment on which the car is traveling.
This is an individual project; working together must be limited to asking specific questions about Racket functionality.
As always, follow the design recipe and make sure your code conforms to the specifications. Function names and argument order must be followed precisely. I may test your program with code of my own so errors at testing time will result in significant penalties even if your code ‘works’ with your own tests.
You will need to rotate the vehicle's image according to the orientation of the current road segment. Rotating an image requires an angle in degrees. Using the end-points of a roadsegment you can compute the slope. Trigonometric functions can give you the angle (in radians) of a given line segment's slope.
Posns can represent vectors (arrows representing direction and magnitude) from the origin. The utilities you need to write support adding and subtracting vectors (represented as posns) as well as stretching and shrinking the lengths of vectors (again, represented as posns).
Do not forget to include the standard acknowledgements header at the top of your file. To grade this deliverable, I will review your code (including signatures, purpose statements, indentation, etc.), and then call big-bang with your your update-vehicle and place-vehicle functions, together with a roadsegment of my choosing.
Submit a single file with your username followed by “P1.rkt” as the name of the file, which should contain your code fulfilling the requirements as well as your acknowledgements.