How can I convert cartesian coordinates to polar coordinates using function
By : Robbedpython
Date : March 29 2020, 07:55 AM
it helps some times Don't you want to use MATLAB's function CART2POL? If you look inside it just do this: code :
th = atan2(y,x);
r = hypot(x,y);
|
calabash-android: "y" and "center_y" coordinates offset by 222 when running query("*") thr
By : Emanuel Silivasan
Date : March 29 2020, 07:55 AM
I wish did fix the issue. It turns out that the offset appeared on this screen in the app as the keyboard was visible on the prior screen. Clicking to generate a pop up while the keyboard was visible caused calabash to read the location of the view while the keyboard was still present, or at least in the process of disappearing, hence the "y" and "center_y" coordinates were raised a few hundred pixels.
|
Trying to add an image to a polar plot gives "Error: annotation_custom only works with Cartesian coordinates"
By : Les Blake
Date : March 29 2020, 07:55 AM
I hope this helps . Gregor's suggestion for using the cowplot library has got me there. Following the introduction to cowplot you can use the draw_grob function to overlay images as you like. It takes a bit of tweaking as the position changes depending on the dimensions of the plot, but its possible. code :
# install.packages("RCurl", dependencies = TRUE)
library(RCurl)
myurl <- "http://vignette2.wikia.nocookie.net/micronations/images/5/50/German_flag.png"
# install.packages("png", dependencies = TRUE)
library(png)
img <- readPNG(getURLContent(myurl))
# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)
ger <- grid::rasterGrob(img, interpolate=TRUE)
g <- ggplot(mtcars, aes(x=mpg, y= cyl)) + geom_line() + coord_polar()
# install.packages("cowplot", dependencies = TRUE)
library(cowplot)
h <- ggdraw(g)
## tweak this to fit your plot
h + draw_grob(ger, 0.4, 0.48, 0.07, 0.07)
|
How do you convert between polar coordinates and cartesian coordinates assuming north is zero radians?
By : Sachin Sangle
Date : March 29 2020, 07:55 AM
hop of those help? Typical polar coordinates 0 points to the East and they go counter-clockwise. Your coordinates start at the North and probably go clockwise. The simplest way to fix you code is to first to the conversion between angles using this formula: code :
flippedAngle = π/2 - originalAngle
public double bearingTo(Vector target) {
return Math.PI/2 - (Math.atan2(target.getY() - y, target.getX() - x));
}
public static Vector fromPolar(double magnitude, double angle) {
double flippedAngle = Math.PI/2 - angle;
return new Vector(magnitude * Math.cos(flippedAngle),
magnitude * Math.sin(flippedAngle));
}
public class Vector {
private final double x;
private final double y;
public Vector(double xIn, double yIn) {
x = xIn;
y = yIn;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getR() {
return Math.sqrt((x * x) + (y * y));
}
public double getTheta() {
return flippedAtan2(y, x);
}
public double bearingTo(Vector target) {
return flippedAtan2(target.getY() - y, target.getX() - x);
}
public static Vector fromPolar(double magnitude, double angle) {
double flippedAngle = flipAngle(angle);
return new Vector(magnitude * Math.cos(flippedAngle),
magnitude * Math.sin(flippedAngle));
}
// flip the angle between 0 is the East + counter-clockwise and 0 is the North + clockwise
// and vice versa
private static double flipAngle(double angle) {
return Math.PI / 2 - angle;
}
private static double flippedAtan2(double y, double x) {
double angle = Math.atan2(y, x);
double flippedAngle = flipAngle(angle);
// additionally put the angle into [0; 2*Pi) range from its [-pi; +pi] range
return (flippedAngle >= 0) ? flippedAngle : flippedAngle + 2 * Math.PI;
}
}
|
R: Converting cartesian coordinates to polar coordinates, and then calculating distance from origin
By : Indian Caravans
Date : March 29 2020, 07:55 AM
I hope this helps you . For x-y coordinates that are in the same units (e.g. meters rather than degrees of latitude and degrees of longitude), you can use this function to get a data.frame of jump sizes and turning angles (in degrees).
|