|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--morey.spore.RPolygon
a regular polygon with unit length sides. This fundamental class has two functions that it serves the shape of the spores as well as the shape of the claims. Since these objects are meant to be passed around a lot the only the essential information is kept. The essentials are:
one and two.
Here is a link to the source code
Spore,
Link, Serialized Form| Field Summary | |
protected static int |
EAST
references to the worlds edge (a temperary thing) |
protected int |
heading
the heading relative to the remembered side. |
protected static int |
highestSerialID
|
protected static java.lang.Object |
junk
|
protected static double[] |
knownAngles
the table of known angles for the number of sides |
protected static double[] |
knownAreas
the table of known areas for the number of sides |
protected static double[] |
knownMinRadii
the table of known inner radii for the number of sides |
protected static double[] |
knownRadii
the table of known outer radii for the number of sides |
protected static int |
MAX_NUM_REC
the maximum number of sides which the tables apply |
protected static int |
NORTH
references to the worlds edge (a temperary thing) |
protected double[] |
one
the first point of the remembered side. |
protected static double |
RADBREATH
the spacing between spores and claims!!! so that spores don't bump into their progeny automatically |
protected int |
serialID
|
protected int |
sides
the number of sides the polygon has |
protected static int |
SOUTH
references to the worlds edge (a temperary thing) |
protected double[] |
two
the second point of the remembered side. |
protected int |
type
the type of polygon (right now I think of this as the colour) |
protected static int |
WEST
references to the worlds edge (a temperary thing) |
| Constructor Summary | |
RPolygon(int sides)
simple constructor for a regular polygon. |
|
RPolygon(int sides,
double[] one,
double[] two,
int type)
constructor for a regular polygon. |
|
| Method Summary | |
double |
angle()
compute the angle that two sides meet at. |
static double |
angle(int n)
compute the angle that two sides meet on a polygon with n sides. |
double |
area()
compute the area of the RPolygon |
static double |
area(int n)
compute the area of the RPolygon with n sides |
java.lang.Object |
clone()
|
boolean |
collision(RPolygon p,
double x,
double y)
compute if a collision of RPolygons has occured. |
boolean |
collisionBoundary(int dir,
double cutoff)
the temporary method is here to impose a boundary. |
void |
correctHeading()
make the current side the one in the direction of the heading. |
static double |
distance(double[] p1,
double[] p2)
compute the distance between p1 and p2. |
boolean |
equals(java.lang.Object obj)
|
static double |
findAngle(double[] p1,
double[] p2)
compute the angle of p2 around p1. |
void |
flip()
flips the polygon over the side that it is heading. |
double[] |
getCentre()
compute the centre of the RPolygon |
void |
getNewSerialID()
used to add the RPolygon into a hashTable |
double[][] |
getPoints()
Compute all the vertices of the RPolygon. |
java.awt.Polygon |
getPolygon(int w,
int h,
double sx,
double sy)
a scaled translated drawing of the polygon. |
int |
getSides()
accessor to number of sides. |
int |
getType()
accessor of type. |
int |
hashCode()
used to add the RPolygon into a hashTable |
void |
left()
change the heading of the polygon one side to the left |
double |
minRadius()
compute the inner radius of this RPolygon |
static double |
minRadius(int n)
compute the inner radius of the RPolygon with n sides |
double |
radius()
compute the outer radius of this RPolygon |
static double |
radius(int n)
compute the outer radius of the RPolygon with n sides |
void |
right()
change the heading of the polygon one side to the right |
void |
setType(int newType)
allows for changing types. |
java.lang.String |
thePoints()
get a string of all the vertices (for debugging) |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
protected static int highestSerialID
protected static java.lang.Object junk
protected int serialID
protected static final int NORTH
protected static final int WEST
protected static final int SOUTH
protected static final int EAST
protected static final int MAX_NUM_REC
protected static final double RADBREATH
protected static double[] knownAreas
protected static double[] knownAngles
protected static double[] knownRadii
protected static double[] knownMinRadii
protected int type
protected int sides
protected double[] one
protected double[] two
oneprotected int heading
one| Constructor Detail |
public RPolygon(int sides)
pre: sides is greater than 1
sides - the number of sides of the new regular polygon
public RPolygon(int sides,
double[] one,
double[] two,
int type)
pre: one is distance 1 away from two
sides - the number of sides of the new regular polygonone - the first point of a side of the new regular polygontwo - the second point of a side of the new regular polygontype - the type/team/colour of the new regular polygon| Method Detail |
public int getType()
public void setType(int newType)
public int getSides()
public double area()
public static double area(int n)
n sidesn - the number of sides the polygon hasn sidespublic double radius()
public static double radius(int n)
n sidesn - the number of sides the polygon hasn sidespublic double minRadius()
public static double minRadius(int n)
n sidesn - the number of sides the polygon hasn sidespublic double angle()
public static double angle(int n)
n sides.n - the number of sides the polygon hasn sides
public static double findAngle(double[] p1,
double[] p2)
p1 - a pointp2 - another point
public static double distance(double[] p1,
double[] p2)
p1 - a pointp2 - another pointpublic double[] getCentre()
public boolean collision(RPolygon p,
double x,
double y)
The code is a little complicated and requires a diagram... I have a hunch that it is efficient but I will need to look into it one day.
p - the polygon to check if it overlaps this one.x - for future usey - for future useRADBREATH
public boolean collisionBoundary(int dir,
double cutoff)
pre: dir must be NORTH, EAST, SOUTH, or WEST.
dir - is the direction to be checkedcutoff - is the distance range (depends on dir)public void right()
public void left()
public void flip()
correctHeadingpublic void correctHeading()
public java.awt.Polygon getPolygon(int w,
int h,
double sx,
double sy)
w - the x coordinate of originh - the y coordinate of originsx - the scaling factor in the x coordinatesy - the scaling factor in the y coordinatePolygonpublic double[][] getPoints()
RPolygon.correctHeading()public java.lang.Object clone()
public java.lang.String toString()
public java.lang.String thePoints()
public int hashCode()
public void getNewSerialID()
public boolean equals(java.lang.Object obj)
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||