# Tag Info

## New answers tagged angles

1

My solution, using the Brensenham algorithm as suggested by Sam Hocevar: public static Point[] brensenham(Point p1, Point p2) { final ArrayList<Point> points = new ArrayList<Point>(); // BRENSENHAM the line across final int dx = abs(p2.x-p1.x), sx = p1.x<p2.x ? 1 : -1; final int dy = -abs(p2.y-p1.y), sy = p1....

0

To space points on a line can be done several ways. Where the line is defined with x1 = ? // line start y1 = ? x2 = ? // line end y2 = ? To get a point on the line via a fraction of the line length pointAt = ? // 0 to 1 are on the line // less than 0 is before the line greater than 1 is after the line px = (x2-x1) * pointAt + x1; py = (...

2

This is a straightforward application of the Unit Circle, multiplied by the length of the vector we want as output: x = length * cos(angle) y = length * sin(angle)

1

angle_difference is calculated with atan2 function which returns -PI to +PI (-180 deg to +180 deg). That is useful because if angle_difference > 0 you know it is clockwise from you and < 0 counterclockwise. your else if statement with <= should only be <, which is causing your oscillation.

0

I think probably your directToTarget is off by 180 degrees somehow. Maybe post that code. That could explain why your turret is always pointing away from the target. The next thing to consider is the oscillation. This is probably happening because you increment by 3 even if the difference between the angle and the desired angle is only 1 - so you'll get some ...

Top 50 recent answers are included