Back to DFS's Workshop Page
Back to Agenda Page
Center of Gravity Problem
For this problem, you are to cannibalize any available code (such as that discussed in Graphics on the Fly) and write a trio of scripts which will allow up to five masses to be placed on a Cartesian grid and will calculate and show the center of gravity for this system.
- The HTML Page: centerofgravity.html
- Ask the user for up to five (x,y) coordinate pairs and a mass at each
- Accept input in a form
- Using the Graph! button, send the data (as three one-dimensional arrays; see Passing an Array) to a PHP script called centerofgravity.php
- The Driver PHP Script: centerofgravity.php
- Since you cannot return values from the script which creates the graph, you need to do the calculations in this script to report where the center of gravity is
- Report the coordinates of the center of gravity
- Call the drawcenterofgravity.php script as the source attribute for an image tag, passing all necessary data, to have the graph created
- The Graphics PHP Script: drawcenterofgravity.php
Using all of the information passed to it by centerofgravity.php, create a PNG utilizing different, coordinated, contrastive colors to draw the following.
- Use the code discussed in Graphics on the Fly to create the axes
- Draw a circle for each mass, having the area of the circle correspond to the mass, the largest one having a standard diameter such as 100 pixels
- Draw a small circle of a different sort of color to indicate the location of the center of gravity
To see how this could work, view this possible solution.
© 2005 DFStermole
Created 7 Dec 05
Last Modified 8 Dec 05