All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sim.app.tutorial6.Body Maven / Gradle / Ivy

Go to download

MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.

The newest version!
/*
  Copyright 2006 by Sean Luke and George Mason University
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

package sim.app.tutorial6;
import sim.engine.*;
import sim.util.*;

public class Body implements Steppable
    {
    private static final long serialVersionUID = 1;

    public double velocity; 
    public double distanceFromSun; 
    
    public double getVelocity() { return velocity; }
    public double getDistanceFromSun() { return distanceFromSun; } 
        
    public Body(double vel, double d) 
        { 
        velocity = vel;  distanceFromSun = d; 
        }
        
    public void step(SimState state)
        {
        Tutorial6 tut = (Tutorial6) state;
        if (distanceFromSun > 0)  // the sun's at 0, and you can't divide by 0
            {
            double theta = ((velocity / distanceFromSun) * state.schedule.getSteps())%(2*Math.PI) ;  
            tut.bodies.setObjectLocation(this, 
                new Double2D(distanceFromSun*Math.cos(theta), distanceFromSun*Math.sin(theta)));
            }
        }
    }    
 




© 2015 - 2025 Weber Informatics LLC | Privacy Policy