I want to draw a line on a canvas. Therefore I use two clicks from the user to define start point S
and end point E
.
ctx.moveTo(sx, sy);
ctx.lineTo(ex, ey);
I further want to substract a static offset on both sides of the line, eg static int offset = 10;
My problem is: how can I know about the direction (north, east, south, west) to which I have to add or substract the offset?
If the line goes from top to bottom, I would have to apply (0, +10)
on the start point S, and (0, -10)
on the end point. Getting mor complicated when the line goes diagonal through the coordinate space.
Probably that might be a "simple" mathematical problem, but I'm missing the right keywords to find any solutions.