In this ActionScript reference on the atan2 function, it reads:
Computes and returns the angle of the point y/x in radians, when
measured counterclockwise from a circle's x axis (where 0,0 represents
the center of the circle). The return value is between positive pi and
negative pi. Note that the first parameter to atan2 is always the y
coordinate.
For example
Math.atan2(0.7071, -0.7071)
(note that the first parameter is the Y coordinate) returns 2.356, which is positive Pi*3/4.
But in Flash graphics the Y axis goes down, not up. Shouldn't it be "clockwise" instead?
This is the general description of what the atan2 function does in all programming languages.
With that said, you have to indeed put atan(-dy,dx) to get the counter-clock wise angle in screen coordinates, or atan2(dx,dy) to get the zero angle pointing upwards.
Related
I am trying to create a graph calculator and making it display the graph correctly on a "canvas". When I load the HTML file and write x e.g it starts from the upper left corner and goes down to the lower right corner. So the problem is that it displays the graph upside down and it does not include negative values.
I know that the canvas starts from (0,0) in pixel value in the upper left corner and ends at (300,300) in the lower right corner. I want it to display something like the green canvas from this link: http://www.cse.chalmers.se/edu/course/TDA555/lab4.html
points :: Expr -> Double -> (Int,Int) -> [Point]
points exp scale (x, y) = [(x, realToPix (eval exp (pixToReal x))) | x<-[0..(fromIntegral canWidth)] ]
where
pixToReal :: Double -> Double --converts a pixel x-coordinate to a real x-coordinate
pixToReal x = x * 0.02
realToPix :: Double -> Double --converts a real y-coordinate to a pixel y-coordinate
realToPix y = y / 0.02
You're probably used to working with 2D coordinate systems where positive y is up, but as you noted in HTML canvas positive y goes down. To simulate the coordinate system you want, you need to flip all the y-values over the line y=0 (aka the x-axis).
Here are a few y-values and their corresponding corrections you can use as tests. Note that I'm assuming y has already been scaled properly; it looks like you've already got that part.
150 -> 0
0 -> 150
-150 -> 300
The pattern is y_new = -(y_old - 150) where 150 is canvas_height/2. Therefore, after scaling you need to apply this formula to all your y values.
To shift the y-axis to the center you need to do the same sort of thing to derive the appropriate linear transformation.
I am using the Octave plot function to plat a 2D graph. I want to scale the x axis by 2x (no change to y axis). i.e. the distance between each unit in x axis is doubled.
How do I do that in Octave?
You have to use the parameter "dataaspectratio" of the function "set" to modify the aspect ratio of the plot (as the self explaining parameter name indicates). dataaspectratio accepts a 3-element vector, with the scales for X,Y and Z, so if you want X to be double as the Y axis scale you should use:
set(gca,'dataaspectratio',[2 1 1])
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.
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.
I have a rectangle, and a circle inside that rectangle (that sits around the center of the rectangle). I want to generate a random 2-component vector that falls inside the rectangle, but not the circle. How can I do it?
Edit: I'd prefer a method that i can use to generate a vector that meets these constraints without brute-forcing it.
Vector = Rectangle.RandomVector();
while (Circle.Contains(Vector)) {
Vector = Rectangle.RandomVector();
}
Aka, just brute force it. It has a 21.5% chance of being outside the circle every time :)
Generate random numbers for the x and y component of the vector such that x < rectangle.width and y < rectangle.heigth. Then check whether x^2 + y^2 < circle.radius^2 and throw the vector away if so.
Update: Another way which generates a non uniform distribution but doesn't throw away any vector is as follows: Randomly choose an angle from the interval 0 to 2*pi. Now determine the length of the vector by randomly choosing a value from the interval determined by the intersections of the line with the former angle starting at the center with the circle and the rectangle.
The resulting distribution will be uniform when protected onto the circle. It will also be uniform for each angle. It wont be uniform in the plane however.