# Compute angles and thereby endpoints in a raster grid?

I am at the moment having some issues with computing an endpoint in a raster grid that is also a valid position in a graph. I am trying to draw a line between these two points, but as the point I am computing becomes negative, its position becomes invalid.

How do I compute the right endpoint value within a 20x20 matrix where my start point is $(10,10)$, and the endpoint has to be 10 steps away from the center at any angle?

This is how I compute the angle now:

coordinate endpoint(double angle, coordinate start, int lenght)
{

double x2 = start.first + (lenght * cos(radians));
double y2 = start.second + (lenght * sin(radians));

return std::make_pair(round(x2),round(y2));
}

• Could you provide more detail on what the exact problem is? The only problem you describe is about negative coordinates. A circle of radius 10 around $(10, 10)$ barely reaches zero. Even if there are numerical errors leading to values slightly below zero, after rounding these should be gone.
– Nero
Dec 10, 2015 at 16:24
• It would also be useful to see the output for a variety of different input values. Dec 11, 2015 at 0:22