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

<p>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?</p>

<p>This is how I compute the angle now: </p>

<pre><code>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));
}
</code></pre>

CC BY-SA 3.0
2015-12-10T16:24:12.387Z
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
CC BY-SA 3.0
2015-12-11T00:22:00.550Z
It would also be useful to see the output for a variety of different input values.
trichoplax is on Codidact now
<mathematics><raster-image><triangulation><debugging>
Compute angles and thereby endpoints in a raster grid?
Bob Burt
# Compute angles and thereby endpoints in a raster grid?

(Asked by: username_0 on 2015-12-09)

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));
}

```

**Tags:** mathematics, raster-image, triangulation, debugging

> **Comments:**
> **username_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.  
> **username_2**: It would also be useful to see the output for a variety of different input values.  

---

## 0 answers

