3

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));
}
Nero
  • 1,310
  • 3
  • 15
  • 31
Bob Burt
  • 183
  • 4
  • 1
    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 '15 at 16:24
  • It would also be useful to see the output for a variety of different input values. – trichoplax is on Codidact now Dec 11 '15 at 00:22

0 Answers0