Home > Software engineering >  Canvas arc() - getting coords before and after
Canvas arc() - getting coords before and after

Time:10-24

I am working on a function that can resolve the coordinates ( X and Y ) of arc function before it started to drawing ( where the arc begins ) and after it is finished ( where the arc ends ).

I tried this code:

export const arcEndCoords = (coordX: number, coordY: number, radius: number, angle: number) => {
    angle = angle * Math.PI / 180;
    return [coordX   Math.cos(angle) * radius, coordY   Math.sin(angle) * radius];
}

but it doesn't have the startAngle and endAngle ( Without startAngle this code won't show the right results )

Could someone write functions for getting the start coords and end coords of the arc function in canvas?

CodePudding user response:

Modify your function as

export const arcEndCoords = (coordX: number, coordY: number, radius: number, angle: number, startAngle: number) => {
    const alpha = (angle   startAngle) * Math.PI / 180;
    return [coordX   Math.cos(alpha) * radius, coordY   Math.sin(alpha) * radius];
}

Otherwise this is not solvable (like for given center, radius and angle there is an infinite number of solutions) as already pointed out.

enter image description here

  • Related