Java Reference
In-Depth Information
Polygon shape # new Polygon();
// the device's shape in local coords
Robot robot; // a reference to the robot
Position robotPos # new Position();
// the robot's current position
Position localPos;
// the device position on the robot
public Device(String name, Robot robot,
Position local, Environment env) {
this .name # name;
this .robot # robot;
robot.readPosition( this .robotPos);
this .localPos # local;
this .environment # env;
// this method is invoked when the geometric shape of the
// device is defined
public void addPoint( int x, int y) {
shape.addPoint(x, y);
// draws the device's geometric shape on the graphical
// interface
public void paint(Graphics g) {
// reads the robot's current position
// draws the shape
Polygon globalShape # new Polygon();
Point2D point # new Point2D.Double();
for ( int i # 0; i < shape.npoints; i !! ) {
point.setLocation(shape.xpoints[i], shape.ypoints[i]);
// calculates the coordinates of the point
// according to the local position
// calculates the coordinates of the point
// according to the robot position
// adds the point to the global shape
globalShape.addPoint(( int )Math.round(point.getX()),
( int )Math.round(point.getY()));
((Graphics2D) g).drawPolygon(globalShape);
Class Platform inherits from the abstract class Device and defines the
shape of the robot's platform. Its local position is set to zero since the
platform's reference frame coincides with the robot's reference frame.
Search WWH ::

Custom Search