Is there a way in javascript to plot x,y coordinates so they fall into a circle rather than a square?
For example if I have the following code:
circleRadius = 100;
context.drawImage(img_elem, dx, dy, dw, dh);
I need to figure out a combination of x,y values that would fall inside a 100 pixel circle.
Thanks!
x^2 + y^2 = r^2
, which in your case equals 100^2 = 10000y^2 = 10000 - x^2
, therefore the points with a chosen x andy = +/-sqrt(10000 - x^2)
will lye on the circle.EDIT: In JS:
Another edit: a jsFiddle Example
Not sure if this is correct JavaScript code, but something like this:
not sure what you mean for javascript but
x = R*cos(theta)
andy = R*sin(theta)
are the Cartesian points for a circle. R is the radius of course and theta is the angle which goes from 0 to 2*Pi.I'm posting this as a solution because this question was the only relevant result in google.
My question/problem was how to add cartesian coordinates inside a circle where
x
andy
would not exceedr
.Examples:
Solution
If you want equidistributed coordinates you better go for
If you want more points close to the middle then use
instead.