protected void drawRobotOverlay(Vector2d robotCenter, double rO, int spacing) { int ovalSize = (int) (spacing * 2.5); graphics.setColor(Color.BLACK); graphics.drawOval( (int) robotCenter.x - ovalSize / 2, (int) robotCenter.y - ovalSize / 2, (int) ovalSize, (int) ovalSize); Vector2d robotFront = new Vector2d(Math.cos(rO) * ovalSize / 2.5, Math.sin(rO) * ovalSize / 2.5); robotFront.add(robotCenter); Vector2d robotCenterLeft = new Vector2d(robotCenter); robotCenterLeft.add( new Vector2d(10 * Math.cos(rO + Math.PI / 2), 10 * Math.sin(rO + Math.PI / 2))); Vector2d robotCenterRight = new Vector2d(robotCenter); robotCenterRight.add( new Vector2d(10 * Math.cos(rO - Math.PI / 2), 10 * Math.sin(rO - Math.PI / 2))); graphics.drawPolygon( new int[] {(int) robotCenterLeft.x, (int) robotCenterRight.x, (int) robotFront.x}, new int[] {(int) robotCenterLeft.y, (int) robotCenterRight.y, (int) robotFront.y}, 3); }
protected void drawRobotWheels( int column, int row, int spacing, double robotOrientation, Vector2d robotCenter, double wheelAngle, int len) { int wheelSize = spacing / 5; Vector2d wheelCenter = new Vector2d(column * spacing, row * spacing); wheelCenter.rotate(robotOrientation); wheelCenter.add(robotCenter); Vector2d posB = new Vector2d(wheelCenter); Vector2d rot = new Vector2d(len * Math.cos(wheelAngle), len * Math.sin(wheelAngle)); posB.add(rot); Vector2d guidingLineCenter = new Vector2d(wheelCenter); rot = new Vector2d(len * Math.cos(robotOrientation), len * Math.sin(robotOrientation)); guidingLineCenter.add(rot); Vector2d guidingLineLeft = new Vector2d(wheelCenter); rot = new Vector2d( len * Math.cos(robotOrientation + Math.PI / 4), len * Math.sin(robotOrientation + Math.PI / 4)); guidingLineLeft.add(rot); Vector2d guidingLineRight = new Vector2d(wheelCenter); rot = new Vector2d( len * Math.cos(robotOrientation - Math.PI / 4), len * Math.sin(robotOrientation - Math.PI / 4)); guidingLineRight.add(rot); Graphics2D gx = (Graphics2D) graphics; // guiding lines gx.setColor(Color.LIGHT_GRAY); gx.drawLine( (int) wheelCenter.x, (int) wheelCenter.y, (int) guidingLineLeft.x, (int) guidingLineLeft.y); gx.drawLine( (int) wheelCenter.x, (int) wheelCenter.y, (int) guidingLineRight.x, (int) guidingLineRight.y); gx.drawLine( (int) wheelCenter.x, (int) wheelCenter.y, (int) guidingLineCenter.x, (int) guidingLineCenter.y); // actual line gx.setStroke(new BasicStroke(2)); gx.setColor(Color.RED); gx.drawOval( (int) wheelCenter.x - wheelSize, (int) wheelCenter.y - wheelSize, wheelSize * 2, wheelSize * 2); gx.drawLine((int) wheelCenter.x, (int) wheelCenter.y, (int) posB.x, (int) posB.y); gx.setStroke(new BasicStroke()); }