Formula to find points on the circumference of a circle, given the center of the circle and the radius - center

I am working on code to find the points on the circumference of a circle. I have the center point of the circle and the radius and I need to draw a circle around it. This will help me define the boundary. Please help me with formula for finding the these points on the circumference.

For a circle with origin (j, k) and radius r:
x(t) = r cos(t) + j
y(t) = r sin(t) + k
where you need to run this equation for t taking values within the range from 0 to 360, then you will get your x and y each on the boundary of the circle.
For more information:
http://www.math.com/tables/geometry/circles.htm

Related

How to convert flash circle object coordinates for canvas/raphael.js?

I have some simple flash animations that I am converting into HTML5 image maps, that trigger some drawing upon <area> rollovers.
Problem being is that all the circles (representing roll-over points) are given to me as flash circle object coordinates. The points in question are formed at the joining of imaginary lines that go from the circle’s topmost and leftmost points (marked by the dashed red lines in the image below).
But to draw my circles in HTML5 (using raphael.js currently), I have to to give a center coordinate: var c = paper.circle(x, y, radius).
So, for example, if I have flash circle object (532.20,30.35) with a height and width of 19.80 (again from the point where the imaginary lines intersect) how can I calculate the values I need for drawing a circle at its center point in the canvas?
You just subtract the radius from the x and y:
x = x - radius;
y = y - radius;
In your case:
radius = 19.8 * 0.5
x = 532.2 - radius;
y = 30.35 - radius;
This will draw the circle center at the original x and y (it moves the circle left and up).
If you want the circle in the effectively same position as the original but have to move the coordinate system then you add radius instead.

how do i create a circle Geometry with a radius and co-ordinates of center, using MySQL Spatial Extensions?

I am trying to create a Circle Geometry in MySQL using the co-ordinates of the center and a radius. I searched everywhere...all i could find in the MySQL doc on the site were for polygons. May be i am looking in the wrong place. can anybody help me with an appropriate SQL that can help me create a table that stores this Circle geometry as one of the columns in the table?
Also, i am not even sure if there is a way to do so in MySQL?..The version i am using is MySQL 5.6.
Thanks in advance.
As of MySQL v5.6.1, you can use Buffer(g, d):
Returns a geometry that represents all points whose distance from the geometry value g is less than or equal to a distance of d.
Obviously, in your case g should be the point at the centre of the circle and d should be its radius.
There are two Parts:
A.For given tested points you have to check their relation with given circle.
B.You want to generate points on circumference of given circle.
A.Yes, First of all take the distance between your given point(test Point) and the centre of circle point. Both of these points are defined in Latitude and longitude. Distance formula between two points(x1,y1) and (x2,y2) is distance d= sqrt[ (x2-x1)^2 + (y2-y1)^2 ].
Now,
If this distance is less than radius of circle then your tested point is inside your circle.
If this distance is Greater than radius then tested point is outside the circle.
If this calculated distance is equal to radius of circle then this tested point is on your circle i.e. on the circumference of your circle.
B. In a circle the total angle theta is 360 degree or 2*Pi in radians.
For given Circle whose centre is (x1, y1) and radius is r.
x = x1 + r * cos(theta)
y = y1 + r * sin(theta)
where, theta is running from Zero to 2*Pi and Pi is 3.1415.
Depending upon how you do it. Example: if you wants 10 points on circle, then increment=(2*Pi-Zero)/10.
fist theta is zero, then theta is Zero+increment, then theta is Zero +increment+increment i.e. 2* increment and then zero + 3*increment and then so on. unless you get theta equal to 2*Pi.
For all above thetas calculate x and y. These all x and y coordinate points are on the circumference of the circle.

Google Maps pixel height by latitude

In Google maps, the closer one gets to the pole, the more strechted out the map gets and sp each pixel of map represents less movment (asymtotically to 0 at the north pole)
I'm looking for a formula to connect the width of a pixel in degrees to the latitute (i.e. the real world distance represented by a pixel on the map). I have some data points here for zoom level 12 (IIRC)
Lat Width
0 0.703107352
4.214943141 0.701522096
11.86735091 0.688949038
21.28937436 0.656590105
30.14512718 0.60989762
35.46066995 0.574739011
39.90973623 0.541457085
41.5085773 0.528679228
44.08758503 0.507194173
47.04018214 0.481321842
48.45835188 0.468430215
51.17934298 0.442887842
63.23362741 0.318394373
72.81607372 0.208953319
80.05804956 0.122131316
90 0
The reason for doing this is I want to input lat/lng pairs and sort out exactly what pixel they would be located with respect to 0,0
I might be wrong but are you sure thos points are the pixel height? They seem to be a cosine which would be the pixel width not the height.
After a little trigonometry the pixel height adjusts to the formula:
where R is the earth radius, phi is the latitude and h is the height of a pixel in the equator.
This formula does not adjust to your points, that's why I asked if it was the width instead.
Anyway if you want so much precision that you cannot use the approximation in the previous answer you should also consider the R variable with the latitude and even with that I don't think you'll get the exact result.
Update:
Then the formula would be a cosine. If you want to take the variable radius of the earth the formula would be:
where R is the radius of the earth and d(0) is your pixel width at the equator. You may use this formula for R assuming the eearth to be an ellipsoid:
with a = 6378.1 (equator) and b = 6356.8 (poles)
While I am not sure what "height of a pixel" means, the plot of data (shown below) seems to fit the equation
y = a + bx + cx^2 + dx^3 where y = height, x = latitude
with coefficients
a = 7.0240278979641990E-01
b = 3.7784208874521786E-04
c = -1.2602864112736206E-04
d = 3.8304225582846095E-07
The general approach to find the equation is to first plot the data, then hypothesize the type of function, and then do a regression to find the coefficients.

Probability of intersection of two users with horizontal accuracy and vision area

I'm receiving data from GPS and store them in MySQL database. I have following columns:
User ID (int)
Latitude (double)
Longitude (double)
Horizontal Accuracy (double)
Horizontal accuracy is radius around Lat/Long, so my user with equivalent probability can be in any point of this area.
I need to find out probability that two users was intersecting. But I also have vision area, which is 30 meters. If horizontal accuracy would be 0 I could just measure area of intersection of two circles that have radius of 30 meters around lat/long. But in my case that's not possible because horizontal accuracy could be in range from 5 to 3000. Usually it's more than my vision area.
I think I can measure area of intersection of two cones where inner circle of this cone will have radius of horizontal accuracy + 30 meters and outer circle will have radius of horizontal accuracy. But this solution seems to be little bit complicated.
I want to hear some thoughts about that and other possible solution.
I've checked MySQL Spatial extension and as far I can see it can't do such calculations for me.
Thanks.
I worked on just such a problem as you are describing. How I approached it was to convert the Lat/Long (world coordinates) into X/Y (Cartesian coordinates) then I applied the Pythagorean Theorem a^2 + b^2 = c^2 to solve the problem.
First you need to convert the Lat/Long Coordinates.
To get X you Multiply the Radius by the cosine (cos) of the angle (NOTE: this angle has to be expressed as radians).
To get Y you do the same as above but use the sine function (sin).
To convert degrees to radials Multiply the angle by the quantity of PI (Approx. 3.14159...) / 180.
Radians = Angle * (PI / 180);
To solve for the c^2 "C Squared" c = SQRT (a*a + b*b);
For more information on Degrees to Radians: http://www.mathwarehouse.com/trigonometry/radians/convert-degee-to-radians.php
For more information on: Converting Lat/Long to X/Y coordinates: http://www.mathsisfun.com/polar-cartesian-coordinates.html
I usually find the information that I need for this kind of problem by asking a question on ask.com.
All the best.
Allan

Connecting arcs on HTML5 Canvas

I am trying to make a donut chart using the arc function in the HTML5 canvas. I am wanting to know how to use the lineTo function to connect two arcs together.
At the moment I have a pie chart which has fixed central x/y coords, so making the slices is easy as once the arc of each slice is done, the lineTo method simply uses the the fixed coords.
However with a ring/donut chart, I have two arcs, one with a smaller radius, but no idea how to connect the ends together without horrifically complicated trigonometry. Is there any way to get the 'start' and 'end' x/y coords of the arc?
I have a current hackyish 'solution' of simply drawing a smaller white circle over the pie chart to give the ring graph, but I want to know the answer to the question above.
You just have to remember a little trigonometry. If your center point is x, y and radius is r; then the coordinates on the circle at an angle alpha are:
pointX = x + Math.cos(alpha) * r;
pointY = y + Math.sin(alpha) * r;
And you have two of those angles, corresponding to the starting and the ending point.
Why are you drawing arcs? Would'nt it be easier if you just draw the circle (or circles for the ring) and then draw radius?