At 2017-04-28T15:31:30+1000, John Gardner wrote: > This might be the wrong forum to ask for help with trigonometry, but I > was planning to announce progress eventually anyway.
I have no experience with pic, but I faintly recall some trig. Maybe I can help. > 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... According to pic.ms, the default radius for an arc is 0.5 inches. I mention this because to convert between angles and arc endpoint coordinates you need to know the radius. The coordinates of the endpoint of the terminal side of an angle are expressed by this relation: Let θ be an angle in radians between the initial (i) and final (f) radii connecting the endpoints of an arc to their common center. Then x and y, the cartesian coordiates of the arc's endpoint are given by x = r cos θ and y = r sin θ where r is the radius of the arc. It sounds like you need the inverse relations, beause you have (x_i, y_i) [startX and startY] and (x_f, y_f) [endX and endY] but you want θ_i and θ_f for the canvas object. Solving for θ we find: θ = arccos(x/r) = arcsin(y/r) The trig functions are periodic, not one-to-one, so you will need to keep track of the signs on x and y so that the θ you find is in the correct quadrant. Be prepared to add or subtract multiples of π/2 to the θ you find to account for the quadrant. My guess is that Kernighan chose the approach he did when designing pic (contra that of the HTML canvas folks) because it preserves more information. Does this help or did I manage to misunderstand you completely? Regards, Branden
signature.asc
Description: PGP signature