|Due date: 5pm, Friday 05 October (week 11). This is a firm deadline: submissions up to 5pm on Saturday 06 October will attract a 15% mark deduction, further submissions may not be accepted thereafter, as marking is done during the week 12 lab.|
The pendulum is an ancient dynamic system, the heart of early timekeeping schemes. A pendulum consists of a mass (we're calling it a ball) and a rod connecting the ball to an anchor point or pin. If friction is ignored, the position of the pendulum at any time t is described by this simple harmonic motion formula:
Write a VBA program that can show a pendulum (or two pendulums, see below) swinging approximately in real time. It must have a form to for the user to enter the pendulum parameters and any simulation variations, and to control the simulation with buttons that allow it to be paused and resumed. The form is to be activated when the sheet "Pendulum" is activated (see lecture examples), and the animation is drawn on the sheet.
The following services are provided in the DrawingLib module
in the template workbook,
read the comments there to understand what they do in more detail.
ClearDrawing - removes all drawing elements from the sheet
DrawVerticalRod - returns a rod shape of given length and top coordinates
DrawBall - returns a circle with basic 3D rendering at given centre and radius
DrawPin - returns a black circle with given centre and radius
Delay - pauses for a given number of milliseconds
CrossHairs - for debugging only - shows where given cordinates are by drawing thin crossed horizontal and vertical lines
Your solution has to integrate form and animation actions, including starting and stopping the simulation (hints on this later). You can inspect and change form element values from VBA code. Much of the solution involves calculating geometric positions, starting with how big the whole picture should be (400 to 500 pixels is sufficient) and where the fixed pin goes. However the real work lies in telling VBA how to display the ball and rod given any angle (angles are conventionally positive to the right of the centre line and minus to the left). There is only one reliable way to do this, so to save wasted effort, here is the approach:
Apart from validation checks on the form values, all VBA code should be in a module, but not named Module1 or Module 2 etc, as these are ignored by the style assessor. The module can have a number of module-level variables to keep track of the simulation state, including shapes, coordinates, and time. It should also have a Public Boolean value that indicates that the simulation is in progress, this variable can be assigned from a button action to pause the simulation (there are neater programming ways, but beyond the scope of the course). Your main loop can then be something like
While simulation is in progress advance time by TIME_UNIT (0.02 seconds is about right) Delay by TIME_UNIT (or a bit less to allow for computations) recalculate angles and positions move objects update form as appropriate DoEvents ' built-in subprogram to update visual elements and respond to user events Wend
The animation can be paused by adding a button to the form and making its Click event procedure change the module-level animating Boolean. This will stop the loop, but the state variables will retain their values until a restart button (or the same button if you like) calls the simulation procedure again. See the week 9 lecture for how to create forms and make them interact with the application.
This assignment is to be completed in groups of either one or two people from the same lab class. Each group will be required to assess the work of three other groups from different lab classes in the week 12 lab. Marks will be reserved for this purpose.
You must register the pair with your tutor no later than the week 10 lab class. Everyone else will be working as a single person.
You must submit the workbook on-line via the Assessments - Manage Assigns link on the class page, which includes the web form at https://cgi.cse.unsw.edu.au/~give/Student/give.php. Choose ENGG1811 and assign2.
Only one member of a pair should submit the file, which must be called ass2_pend.xlsm, as it is stored against the group rather than the individual. Remember to rename the template after you download it.
The number of useful things the program can do is fairly long, but you can get a reasonable pass by completing only some of them. The animation is much more interesting if two pendulums are shown: one using the exact period and one using the approximate period. Change the appearance of the approximate one (DrawingLib.RemovePresetGradient).
Your submission will be assessed by people in three other lab groups, during the week 12 lab class. They (and you) will use an objective marking sheet, so we expect the marks to be quite close. If so, you will receive the median mark, otherwise a tutor will re-mark it and their assessment will be used. If you don't turn up to the lab or complete the assessment (without documented reason) your own mark will receive an 8% deduction. Tutors will only mark submissions where there isn't a consensus.
The provisional allocation of marks (out of 40 so every category is integral) is
|15||Accurate display of a pendulum over at least once cycle||5||Accurate display of a second pendulum using the approximate period, user-selectable||3||Validation of the amplitude and length||5||Ability to start/stop/resume/reset the animation||6||Appearance and usability of the form, including correctly displaying both periods, the current time and angle||6||Style mark (as awarded by AssessStyle)||40||Total mark (rescaled to 5% of the overall assessment)||3||Bonus features or enhanced information|
Up to 3 bonus marks may be awarded if the submission provides additional functionality or information to the user. These include (but are not limited to)