Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
HaB
Jan 5, 2001

What are the odds?
I have been playing around with PaperJS for the last couple of days, and I have some questions - none of which seem to be in the docs (which are still spotty.)

First, it has a built in for describing an Arc. As in - a part of a circle. So common sense (or at least MY common sense) would mean it would look something like:

code:
var myArc = new Arc(circleCenterPoint, circleRadius, numberOfDegrees);
so if I wanted say - a 30 degree arc on a circle centered at (100, 100) with radius 100, I go:
code:
var myArc = new Arc({x:100, y:100}, 100, 30);
instead they want you to use:
code:
var myArc = new Arc(from, through, to);
where from = the starting coordinate of the arc, to = the ending coordinate, and through = a point which the arc passes through.

To which my response is: what in the actual gently caress? Who thinks of an Arc that way? So I only got as far as Algebra 2 in HS, and I'm sure there's some mathematical reason why you can specify an Arc that way, but I have no idea what it is. Playing around with the numbers is not shedding any light on it.

More importantly, can someone tell me how to translate from (center, radius, degrees) to (from, through, to)?

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Given any three distinct points in the plane, either those three points are on the same straight line, or there's a unique circle that passes through them all. In the case where you want an arc of a circle, there's still a unique arc, provided you distinguish one of the points as being "the one in the middle". So at least mathematically you can specify an arc of a circle in that way. Why the library creators chose to have you specify it in that way I don't know.

You say you want to specify an arc using (radius, center, degrees), but what is degrees here? The angle at the centre of the circle? That doesn't tell us where the arc should start or end, unless you mean it to start at North (0 degrees) or something. In other words, if you say you want a circular arc where degrees is 90, how am I to know whether that's the arc that goes from north to east, or from southwest to northwest, or some other arc? Another parameter is needed to tell me (say) where the arc starts.

If the centre of a circle is at (a, b) and it has radius r, and you want the arc that starts at angle x and ends at angle y, then the end points are (a + r cos x, b + r sin x) and (a + r cos y, b + r sin y) and we also need a point on the circumference in between the two angles, which can be (a + r cos z, b + r sin z) where z = (x + y) / 2. I don't know how feasible this is as an approach if you need to draw very many circular arcs in a computationally efficient manner.

HaB
Jan 5, 2001

What are the odds?

Hammerite posted:

Given any three distinct points in the plane, either those three points are on the same straight line, or there's a unique circle that passes through them all. In the case where you want an arc of a circle, there's still a unique arc, provided you distinguish one of the points as being "the one in the middle". So at least mathematically you can specify an arc of a circle in that way. Why the library creators chose to have you specify it in that way I don't know.

You say you want to specify an arc using (radius, center, degrees), but what is degrees here? The angle at the centre of the circle? That doesn't tell us where the arc should start or end, unless you mean it to start at North (0 degrees) or something. In other words, if you say you want a circular arc where degrees is 90, how am I to know whether that's the arc that goes from north to east, or from southwest to northwest, or some other arc? Another parameter is needed to tell me (say) where the arc starts.

If the centre of a circle is at (a, b) and it has radius r, and you want the arc that starts at angle x and ends at angle y, then the end points are (a + r cos x, b + r sin x) and (a + r cos y, b + r sin y) and we also need a point on the circumference in between the two angles, which can be (a + r cos z, b + r sin z) where z = (x + y) / 2. I don't know how feasible this is as an approach if you need to draw very many circular arcs in a computationally efficient manner.

Sorry. Yes - degrees is from the center of the circle, with an arbitrary direction (in this case 'west' or pointing directly left) as 0 degrees. You don't need to know in the context of the library, since you can rotate an arc after the fact to place it where you want. I guess you could pass in a 4th argument as a "starting direction", it's just in this case "0 degrees" is pointing due west.

I was not aware of that 3 points on a plane rule, hence my complete and utter confusion as to why someone would represent an Arc that way. My programming career for nearly 20 years has been all application development stuff, so I have never needed so much math before. Guess I probably need to pick up a book and bone the gently caress up.

Arguably - it's a strange convention on the part of the library creators. They also express circle measurements in degrees, which is unusual - since nearly every other graphics library I have encountered uses radians.

  • Locked thread