Difference between revisions of "Bouncing Polygon Simulator"
Line 1: | Line 1: | ||
=Overview= |
|||
=Polygon Simulator How To’s:= |
|||
<br clear=all> |
|||
=Run a simulation and watch a movie= |
=Run a simulation and watch a movie= |
||
Line 8: | Line 10: | ||
*Object – defines the the polygon/ball |
*Object – defines the the polygon/ball |
||
object.nvert |
|||
is 1 for a ball and the number of vertices for a polygon. |
is 1 for a ball and the number of vertices for a polygon. |
||
object.x |
object.x |
||
defines the x coordinates of the center of mass and vertices of the polygon or ball. If the object is a ball, all that is needed is the centroid of the ball. If the object is a polygon, the user must enter a vector whose first entry is the centroid and succesive entries are the vertices of the polygon. |
defines the x coordinates of the center of mass and vertices of the polygon or ball. If the object is a ball, all that is needed is the centroid of the ball. If the object is a polygon, the user must enter a vector whose first entry is the centroid and succesive entries are the vertices of the polygon. |
||
object.y |
|||
defines the y coordinates of the polygon in the same way. |
defines the y coordinates of the polygon in the same way. |
||
object.r |
object.r |
||
Line 25: | Line 27: | ||
defines the restitution coefficient between the ball and the table. |
defines the restitution coefficient between the ball and the table. |
||
State – defines the initial state of the polygon/ball |
*State – defines the initial state of the polygon/ball |
||
state.x |
|||
defines the initial x position of the center of mass. |
|||
state.y |
|||
defines the initial y position of the center of mass. |
|||
state.theta |
|||
defines the initial theta position of the ball/polygon with respect to object.theta |
|||
state.xd |
|||
defines the initial x velocity of the center of mass. |
|||
state.yd |
|||
defines the initial y velocity of the center of mass. |
|||
state.thetad |
|||
defines the initial rotational velocity about the center of mass |
|||
Table – defines the functions describing the table motion which are entered as strings. |
*Table – defines the functions describing the table motion which are entered as strings. |
||
Table.x |
Table.x |
Revision as of 19:02, 11 June 2009
Overview
Run a simulation and watch a movie
There are three ways to run a simulation. You can run the simulation for a certain amount of time and watch the movie while the simulation is running (option 1). This option is not recommended because it slows down the simulation and the movie lags a lot. Another way is to run the simulation for a certain amount of time and then construct a movie afterwards. The last way is to run the simulation for a certain number of impacts and post-construct the movie.
Before you run a simulation, you must specify the ball-table system.
- Object – defines the the polygon/ball
object.nvert is 1 for a ball and the number of vertices for a polygon. object.x defines the x coordinates of the center of mass and vertices of the polygon or ball. If the object is a ball, all that is needed is the centroid of the ball. If the object is a polygon, the user must enter a vector whose first entry is the centroid and succesive entries are the vertices of the polygon. object.y defines the y coordinates of the polygon in the same way. object.r defines the radius of a ball. The user may enter any value for this if the object is a polygon. object.theta defines the original angle of each vertex in relation to the center of mass. The user does not have to enter this variable. object.inertia defines the inertia of the object. The user must enter this. object.u defines the friction coefficient between the ball and the table. object.res defines the restitution coefficient between the ball and the table.
- State – defines the initial state of the polygon/ball
state.x defines the initial x position of the center of mass. state.y defines the initial y position of the center of mass. state.theta defines the initial theta position of the ball/polygon with respect to object.theta state.xd defines the initial x velocity of the center of mass. state.yd defines the initial y velocity of the center of mass. state.thetad defines the initial rotational velocity about the center of mass
- Table – defines the functions describing the table motion which are entered as strings.
Table.x Defines the x function for the table. Table.y Defines the y function for the table. Table.phi Defines the angle function for the table. Table.xd Defines the x velocity function for the table. The user does not need to enter this unless they are using Matlab without the symbolic toolbox. There are instructions for this specific circumstance. Table.yd Defines the y velocity function for the table and also requires the symbolic toolbox. Table.phid Defines the angular velocity function for the table and requires the toolbox.
Params – defines the miscellaneous parameters for running the simulation.
Params.step Defines the minimum step size to be used during the simulation. Params.stepmov Defines the time step size for view a movie. Params.T defines how long to run the simulation for. The user may enter any value for this if they are using option 3. Params.hitlim Defines how many table-ball impacts the program should simulate. The user may enter any value for this if they are using options 1 or 2. Params.windim Defines the viewing window size for the movie. This is a vector that follows [xmin xmax ymin ymax].
After the user has specified all the necessary information to describe the table-ball system, they may run the polysim function.
[F,contstates,object,table,steplist] = polysim(object,state,table,params,option); 1) F is an array of frames that may be used to construct a movie. F is an empty matrix if the user chose option 2 or 3. 2) contstates is a structure holding the times and object state at each impact. Contstates{1} = times Contstates{2} = impact states which are structures 3) object and table simply return the object and table given by the user 4) steplist returns the list of time steps used during the simulation
Once the simulation has finished running, the user may construct a movie if they chose option 2 or 3.
F = movconstr(contstates,table,params,object);
1) F is an array of frames that may be used to construct a movie.
The user may then convert the set of frames, F, into an avi file. The drawback is that this avi format plays almost only on windows media player.
Movie2avi(‘filename.avi’,F);
Bifurcation Diagrams / Long Time Behavior Plots
[lam,hmax,xpos,vpost,time] = bifDiagram(lam,object,state,table,params);
This program simulate multiple ball-table systems each for a certain number impacts. Each system is different based on parameters ranged by the user. Lam, “lambda”, is a vector containing these parameters. For example, if you want to look at how changing the dorp height of the ball changes the long time behavior of the sytem, you open up bifDiagram.m and input the following at line 22.
State.y = [num2str(lam(ii)),’*1e-2’];
Then specify lambda, the drop height range, which in multiples of 1 cm.
The program returns lam, hmax, xpos, vpost, and time.
1) lam is the same vector entered by the user 2) hmax is a matrix containing the maximum height the ball reaches in between each impact for every simulation run hmax(row,col): row – impacts, col – lamda values 3) xpos is a matrix containing the x position of the ball at each impact. The rows and columns behave the same way as hmax 4) vpost is a matrix containing the post impact velocities 5) time is the time it took to run the bifDiagram program
Trajectory / TrajectoryANDTable
Both trajectory and trajectoryANDTable return the time evolution of the x and y position of the ball/polygon by reconstructing the data from impact states (contstates). The trajectoryANDTable program returns the the time evolution of the x and y position of the table as well.
[t,x,y] = trajectory(contstates,step,t0,t1);
Input: 1) contstates is the same contstates variable that is returned from polysim program 2) step is the stepsize in between data points that you want the trajectory program to output 3) t0 is the starting point for the data construction 4) t1 is the end point for the data construction
Period1
Period1 plots the trajectory of a ball around its period 1 fixed points. It plot three trajectories. One is the the ball exactly at its fixed point. The other two are at points before and after the fixed point.
Functions Used By These Programs
1) zerofinder – A binary serach program that returns the table-ball impact times. 2) datarecon – reconstructs the objects flight data using pre and post imapact states as well as the movie step size specified by the user 3) polyplot – updates the plot frame with the current system state 4) impact – returns the object post impact state based on the system pre impact state
- Sample simulations for each program are contained at the end the polysim and bifDiagram programs