Hot answers tagged

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

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....


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.



Only top voted, non community-wiki answers of a minimum length are eligible