Sorry, I just noticed that your drawing canvas measures the angles clockwise rather than the traditional counterclockwise so you need to negate the y coordinates to atan2:
startAngle = Math.atan2(centreY - startY, startX - centreX) endAngle = Math.atan2(centreY - endY, endX - centreX) -Larry > -----Original Message----- > From: Jones, Larry (DF PL PDS EI US) > Sent: Friday, April 28, 2017 10:27 AM > To: 'John Gardner' <gardnerjo...@gmail.com> > Subject: RE: [Groff] Problems with arcs and angles > > startAngle = atan2(startY - centreY, startX - centreX) > endAngle = atan2(endY - centreY, endX - centreX) > radius = sqrt((startY - centreY) * (startY - centreY) + (startX - centreX) * > (startX - centreX)) > > -Larry > > > -----Original Message----- > > From: Groff [mailto:groff- > bounces+lawrence.jones=siemens....@gnu.org] > > On Behalf Of John Gardner > > Sent: Friday, April 28, 2017 1:32 AM > > To: groff <groff@gnu.org> > > Subject: [Groff] Problems with arcs and angles > > > > Hello! > > > > Some time ago, I announced my intent to build a man-page previewer for a > > text-editor named Atom <https://atom.io/>. Work is coming along nicely: > > this page <https://cdn.rawgit.com/Alhadis/language- > > roff/a7c07744a9d44adf32a546646f7a8d57d52e6e58/preview-tty.html> > > was generated using a lightweight tokeniser > > <https://github.com/Alhadis/language- > roff/blob/renderer/lib/tokeniser.js> > > written in JavaScript, which processes Groff's intermediate output > language > > into web-based formats. That's the nroff preview... I'm now halfway > through > > developing the troff previewer, which uses HTML5 canvas > > <https://developer.mozilla.org/en- > > US/docs/Web/API/CanvasRenderingContext2D> > > technology to draw realtime previews of an opened Roff document. > > > > So far, so good! > > > <https://cloud.githubusercontent.com/assets/2346707/25514878/732e09ea- > > 2c23-11e7-97ea-9674d3845dd1.png> > > I'm > > proud of how this is turning out: bear in mind, that preview updates as the > > user types, so it'll feel like an efficient replacement for a word > > processing > > program, haha. > > > > I'm currently stuck with drawing arcs > > <https://developer.mozilla.org/en- > > US/docs/Web/API/CanvasRenderingContext2D/arc>. > > This > > might be the wrong forum to ask for help with trigonometry, but I was > > planning to announce progress eventually anyway. > > > > Now, this pic code: > > > > .PS > > > "+" at 0,0 > > > arc -> from 0.5,0 to 0,0.5 > > > arc -> cw from 0,0 to 1,0.5 > > > arc -> cw from 0,0 to 2,0 rad 15 > > > .PE > > > > > > ... should look like this > > > <https://cloud.githubusercontent.com/assets/2346707/25515071/4bc46870- > > 2c25-11e7-9883-9248e4b4aa68.png>. > > Instead, it, uh, looks like this > > > <https://cloud.githubusercontent.com/assets/2346707/25515084/5d84eed6- > > 2c25-11e7-8cdd-bdb65f7804e9.png> > > . > > > > Groff's output gives me these coordinates to go by: > > > > - startX, startY - Coordinates of the arc's starting point > > - centreX, centreY - Coordinates of the arc's centre > > - endX, endY - Coordinates of the arc's terminal point > > > > But the canvas arc method I'm working with requires all of these: > > > > - x - The x coordinate of the arc's centre. > > - y - The y coordinate of the arc's centre. > > - radius - The arc's radius. > > - startAngle - The angle at which the arc starts, measured clockwise > > from the positive x axis and expressed in radians. > > - endAngle - The angle at which the arc ends, measured clockwise from > > the positive x axis and expressed in radians. > > > > It's embarrassing to be stuck on something so obvious, but this is what's > > blocking further progress...