org.starhope.appius.geometry
Class Coord3D

java.lang.Object
  extended by org.starhope.appius.geometry.Tuple3D<Coord3D>
      extended by org.starhope.appius.geometry.Coord3D
All Implemented Interfaces:
Serializable, CastsToJSON

public class Coord3D
extends Tuple3D<Coord3D>

A coördinate triplet (x,y,z)

Author:
brpocock@star-hope.org
See Also:
Serialized Form

Field Summary
static Coord3D ORIGIN
          origin point (0,0,0)
private static long serialVersionUID
          Java serialisation unique ID
 
Fields inherited from class org.starhope.appius.geometry.Tuple3D
x, y, z
 
Constructor Summary
Coord3D()
          Create a coordinate set at (0,0,0)
Coord3D(Coord3D proto)
          Copy constructor
Coord3D(double x0, double y0, double z0)
          Creates a coordinate triplet
Coord3D(org.json.JSONObject jso)
          Creates a coordinate triplet from a JSONObject
Coord3D(Point2D p)
           
 
Method Summary
 int compareTo(Object other)
          Since there's no reasonable ordering for 3D points in a linear fashion, I compare their string forms.
 Coord3D constrain(Coord3D minBounds, Coord3D maxBounds)
          Constrain this object's coordinates to be within the given boundaries.
 double distance(Coord3D other)
          Find the distance to another point, from this one.
static double distance(Coord3D a, Coord3D b)
          Subtract two three-dimensional coordinates, returning the absolute distance between them.
 boolean equals(Object obj)
          This is an overriding method.
static Coord3D fromString(String string)
           
 double inverseSquare(Coord3D other)
          Syntactic sugar: This just returns the square root of the distance between two points, as a syntactic sugar for sound- and air-related events.
static double inverseSquare(Coord3D a, Coord3D b)
          Syntactic sugar: This just returns the square root of the distance between two points, as a syntactic sugar for sound- and air-related events.
protected  Coord3D newInstance(double x0, double y0, double z0)
          Method used to create a new object of the child's type while getting around down-casting problems in Java
static Coord3D randomIn(Room aRoom)
          Generate a random 3D coördinate someplace within the volume described by a given room.
 Coord2D toCoord2D()
          Converts the 3D coordinate to a 2D coordinate.
 
Methods inherited from class org.starhope.appius.geometry.Tuple3D
add, add, clone, divide, getX, getY, getZ, hashCode, multiply, subtract, subtract, toJSON, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialisation unique ID

See Also:
Constant Field Values

ORIGIN

public static final Coord3D ORIGIN
origin point (0,0,0)

Constructor Detail

Coord3D

public Coord3D()
Create a coordinate set at (0,0,0)


Coord3D

public Coord3D(Coord3D proto)
Copy constructor

Parameters:
proto - prototype to be copied

Coord3D

public Coord3D(double x0,
               double y0,
               double z0)
Creates a coordinate triplet

Parameters:
x0 - x ordinate
y0 - y abscissa
z0 - z ordinate

Coord3D

public Coord3D(org.json.JSONObject jso)
        throws org.json.JSONException
Creates a coordinate triplet from a JSONObject

Parameters:
jso - JSON object containing "x", "y", and "z" coördinates
Throws:
org.json.JSONException - if the object is malformed

Coord3D

public Coord3D(Point2D p)
Parameters:
p - point
Method Detail

distance

public static double distance(Coord3D a,
                              Coord3D b)
Subtract two three-dimensional coordinates, returning the absolute distance between them.

Parameters:
a - One point;
b - and the other
Returns:
The distance between the two coordinates

fromString

public static Coord3D fromString(String string)
Parameters:
string - A coordinate string as one of: JSON { x:###, y:###, z:### } or (x,y,z) or [x:y:z]
Returns:
WRITEME

inverseSquare

public static double inverseSquare(Coord3D a,
                                   Coord3D b)
Syntactic sugar: This just returns the square root of the distance between two points, as a syntactic sugar for sound- and air-related events.

Parameters:
a - One point
b - The other
Returns:
The square root of the distance

randomIn

public static Coord3D randomIn(Room aRoom)
Generate a random 3D coördinate someplace within the volume described by a given room. Does not make any assertions about the coördinate falling within a usable portion of that volume, e.g. a walkable space.

Parameters:
aRoom - some room
Returns:
a coördinate within the room's described volume

compareTo

public int compareTo(Object other)
Since there's no reasonable ordering for 3D points in a linear fashion, I compare their string forms.

Parameters:
other - the other point
Returns:
the stringwise comparison of the two coördinate triplets

constrain

public Coord3D constrain(Coord3D minBounds,
                         Coord3D maxBounds)
Constrain this object's coordinates to be within the given boundaries.

Parameters:
minBounds - The least they can be;
maxBounds - The most;
Returns:
true if any ordinate was chomped to fit within the range

distance

public double distance(Coord3D other)
Find the distance to another point, from this one. BRP: this is reïmplemented for optimization, rather than just calling the static version, this saves a lot of pointer lookups in a very primitive routine.

Parameters:
other - Some other point
Returns:
The distance

equals

public boolean equals(Object obj)
This is an overriding method.

Overrides:
equals in class Tuple3D<Coord3D>
See Also:
Object.equals(java.lang.Object)

inverseSquare

public double inverseSquare(Coord3D other)
Syntactic sugar: This just returns the square root of the distance between two points, as a syntactic sugar for sound- and air-related events.

Parameters:
other - The other point
Returns:
The square root of the distance

newInstance

protected Coord3D newInstance(double x0,
                              double y0,
                              double z0)
Description copied from class: Tuple3D
Method used to create a new object of the child's type while getting around down-casting problems in Java

Specified by:
newInstance in class Tuple3D<Coord3D>
Parameters:
x0 - x ordinate
y0 - y abscissa
z0 - z ordinate
Returns:
a new instance of the same type, with the given values
See Also:
Tuple3D.newInstance(double, double, double)

toCoord2D

public Coord2D toCoord2D()
Converts the 3D coordinate to a 2D coordinate. Throws an assertion error if the z coordinate is non-zero

Returns:
2D version (assuming that z=0)