# User:Blubex/Snippets

Jump to navigation
Jump to search

## Some bits of code I've put together and posted

```
double x = getX() - getWidth() / 2;
double y = getY() - getHeight() / 2;
double a = Math.toDegrees(Math.atan(x / y));
turnRight(180 - getHeading() + a); // turn to face lower-left corner
// can be replaced by Point2D.distance(0, 0, x, y);
double length = getX();
double height = getY();
double hypotenuse = Math.sqrt(length*length + height*height); //pythagorean theorem
ahead(hypotenuse - 40); //ahead -almost- to the corner. change the 40 to different numbers if you want.
```

This code sends a robot directly to the lower-left corner. How it works is that length and height are calculated and a hypotenuse is gathered. Then it turns current bearing - angle to lower-left corner. (If anyone can explain this better, please do. It's hard for me to understand, so I'm not very good at explaining this.) If you would like to use this code, put it in your run() method. There are a lot of ways you could advance this code for your robot. Some enhancements would be to make the robot choose a corner, such as sample.Corners does. You could also make something to turn a little while moving to the corner, to have more bullet avoidance.

--Blubex 04:59, 19 December 2011 (UTC)