sim.app.woims3d.Vector3D Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mason Show documentation
Show all versions of mason Show documentation
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.woims3d;
import sim.util.Double3D;
public class Vector3D implements java.io.Serializable
{
private static final long serialVersionUID = 1;
public double x;
public double y;
public double z;
public Vector3D( double x, double y, double z )
{
this.x = x;
this.y = y;
this.z = z;
}
public Vector3D( final Double3D d )
{
this.x = d.x;
this.y = d.y;
this.z = d.z;
}
public final Vector3D add( final Vector3D b )
{
return new Vector3D( x + b.x, y + b.y, z + b.z );
}
public final Vector3D add( final Double3D b )
{
return new Vector3D( x + b.x, y + b.y, z + b.z );
}
public final Vector3D subtract( final Vector3D b )
{
return new Vector3D( x - b.x, y - b.y, z - b.z );
}
public final Vector3D subtract( final Double3D b )
{
return new Vector3D( x - b.x, y - b.y, z - b.z );
}
public final Vector3D amplify( double alpha )
{
return new Vector3D( x * alpha, y * alpha, z * alpha );
}
public final Vector3D normalize()
{
if( x != 0 || y != 0 || z != 0)
{
double temp = Math.sqrt( x*x+y*y+z*z );
return new Vector3D( x/temp, y/temp, z/temp );
}
else
return new Vector3D( 0, 0, 0 );
}
public final double length()
{
return Math.sqrt( x*x+y*y+z*z );
}
public final Vector3D setLength( double dist )
{
if( dist == 0 )
return new Vector3D( 0, 0, 0 );
if( x == 0 && y == 0 && z == 0 )
return new Vector3D( 0, 0, 0 );
double temp = Math.sqrt( x*x+y*y+z*z );
return new Vector3D( x * dist / temp, y * dist / temp, z * dist / temp );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy