Class DynamicParticle

All Implemented Interfaces:
PropertyChangeListener, EventListener, Drawable, Interactive, Measurable, Trackable, ODE
Direct Known Subclasses:
DynamicParticlePolar

public class DynamicParticle extends ParticleModel implements ODE
DynamicParticle models a particle using Newton's 2nd law.
Version:
1.0
Author:
W. Christian, D. Brown
  • Field Details

    • modelBooster

      protected org.opensourcephysics.cabrillo.tracker.DynamicParticle.ModelBooster modelBooster
    • cellNumberField

      protected NumberField cellNumberField
    • inSystem

      protected boolean inSystem
    • boosterName

      protected String boosterName
    • cartVars

      protected static final String[] cartVars
    • state

      protected double[] state
    • initialState

      protected double[] initialState
    • solver

      protected ODESolver solver
    • iterationsPerStep

      protected int iterationsPerStep
    • system

      protected DynamicSystem system
    • frameStates

      protected HashMap<Integer,double[]> frameStates
    • temp

      protected double[] temp
  • Constructor Details

    • DynamicParticle

      public DynamicParticle()
      Constructor
  • Method Details

    • getBoostVars

      protected String[] getBoostVars()
    • draw

      public void draw(DrawingPanel panel, Graphics _g)
      Overrides ParticleModel draw method.
      Specified by:
      draw in interface Drawable
      Overrides:
      draw in class ParticleModel
      Parameters:
      panel - the drawing panel requesting the drawing
      _g - the graphics context on which to draw
    • getDisplayName

      public String getDisplayName()
      Gets a display name for this model.
      Overrides:
      getDisplayName in class ParticleModel
      Returns:
      the display name
    • delete

      public void delete()
      Deletes this particle. Overrides ParticleModel method to warn user if this is part of a DynamicSystem.
      Overrides:
      delete in class ParticleModel
    • refreshSteps

      protected void refreshSteps(String why)
      Refreshes step positions.
      Overrides:
      refreshSteps in class ParticleModel
    • reset

      public void reset()
      Resets parameters, initializes solver and sets position(s) for start frame or first clip frame following.
      Specified by:
      reset in class ParticleModel
    • getState

      public double[] getState()
      Gets the current state {x, vx, y, vy, t}.
      Specified by:
      getState in interface ODE
      Returns:
      the state
    • saveState

      protected void saveState(int frameNumber)
      Saves the current state.
      Overrides:
      saveState in class ParticleModel
      Parameters:
      frameNumber - the frame number
    • restoreState

      protected boolean restoreState(int frameNumber)
      Restores the state to a previously saved state, if any.
      Overrides:
      restoreState in class ParticleModel
      Parameters:
      frameNumber - the frame number
      Returns:
      true if state successfully restored
    • getRate

      public void getRate(double[] state, double[] rate)
      Gets the rate {vx, ax, vy, ay, 1} based on a specified state {x, vx, y, vy, t}.
      Specified by:
      getRate in interface ODE
      Parameters:
      state - the state
      rate - the rate of change of the state
    • setSolver

      public void setSolver(Class<?> solverClass)
      Sets the ODESolver type.
      Parameters:
      solverClass - the solver class
    • getInitialState

      public double[] getInitialState()
      Gets the initial state {x, vx, y, vy, t}.
      Returns:
      the initial state
    • getStartFrame

      public int getStartFrame()
      Gets the start frame for this model. Overrides ParticleModel method.
      Overrides:
      getStartFrame in class ParticleModel
      Returns:
      the start frame
    • setStartFrame

      public void setStartFrame(int n)
      Sets the start frame for this model. Overrides ParticleModel method.
      Overrides:
      setStartFrame in class ParticleModel
      Parameters:
      n - the desired start frame
    • getEndFrame

      public int getEndFrame()
      Gets the end frame for this model. Overrides ParticleModel method.
      Overrides:
      getEndFrame in class ParticleModel
      Returns:
      the end frame
    • setEndFrame

      public void setEndFrame(int n)
      Sets the end frame for this model. Overrides ParticleModel method.
      Overrides:
      setEndFrame in class ParticleModel
      Parameters:
      n - the desired end frame
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Description copied from class: ParticleModel
      Responds to property change events.
      Specified by:
      propertyChange in interface PropertyChangeListener
      Overrides:
      propertyChange in class ParticleModel
      Parameters:
      e - the property change event
    • getXYForces

      protected void getXYForces(double[] cartesianState, double[] ret)
      Gets the x- and y-forces based on a specified cartesian state {x, vx, y, vy, t}.
      Parameters:
      cartesianState - the state
      ret - the forces [fx, fy]
    • resetState

      protected void resetState()
      Resets the state variables {x, vx, y, vy, t}.
    • initializeInitEditor

      protected void initializeInitEditor()
      Creates the initial position and velocity parameters.
    • initializeFunctionPanel

      protected void initializeFunctionPanel()
      Creates and initializes the ModelFunctionPanel.
      Specified by:
      initializeFunctionPanel in class ParticleModel
    • getNextTracePositions

      protected boolean getNextTracePositions()
      Gets the next trace positions.
      Returns:
      an array of points at the trace positions
    • setTracePositions

      protected void setTracePositions(double[] state)
      Sets the positions of the trace points based on a specified state.
      Parameters:
      state - the state
    • getBoostState

      protected double[] getBoostState(PointMass target, int frameNumber)
      Gets the cartesian state {x, vx, y, vy, t} of a PointMass at a specified frame number.
      Parameters:
      target - the PointMass
      frameNumber - the frame number
      Returns:
      the state, or null if the point mass is not marked at the frame number
    • getBooster

      protected PointMass getBooster()
      Gets the booster point mass.
      Returns:
      the booster
    • setBooster

      protected void setBooster(PointMass booster)
      Sets the booster point mass.
      Parameters:
      booster - the new booster (may be null)
    • isBoostedBy

      protected boolean isBoostedBy(PointMass target)
      Determines if a specified point mass is a booster of this particle (or a booster of a booster, etc).
      Parameters:
      target - a point mass
      Returns:
      true if the target is a booster
    • boost

      protected void boost()
      Sets the initial conditions to those of the booster at the current start frame.
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an ObjectLoader to save and load data for this class.
      Returns:
      the object loader
    • dispose

      public void dispose()
      Description copied from class: TTrack
      Disposes of resources when this track is deleted or cleared.
      Overrides:
      dispose in class ParticleModel