3
$\begingroup$

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 radians = (M_PI/180)*angle;

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

    return std::make_pair(round(x2),round(y2));
}
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – Nero
    Dec 10, 2015 at 16:24
  • $\begingroup$ It would also be useful to see the output for a variety of different input values. $\endgroup$ Dec 11, 2015 at 0:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.