Created
December 4, 2014 14:06
-
-
Save felixlindemann/9a47881182199e18ba05 to your computer and use it in GitHub Desktop.
vrp-plot helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plottitle <- function(t){ | |
### Plot "Folie ###" | |
plot(NA,NA,frame.plot=FALSE, xlab="", ylab="", xlim= c(-1,1), ylim=c(-1,1), axes=FALSE) | |
text(0,0,t, cex=2, ) | |
} | |
getPolar <- function(n0,n1){ | |
# Polarwinkel berechnung zum vekürzen der Pfeile | |
x1 <- n1$x | |
x0 <- n0$x | |
y1 <- n1$y | |
y0 <- n0$y | |
value<-NULL | |
x<-x1-x0 | |
y<-y1-y0 | |
if(x==0){ | |
if(y>0){ | |
value<-pi/2 | |
}else{ | |
if(y<0){ | |
value<- 3*pi/2 | |
}else{ | |
# warning("Angle can't be calculated because both coordinates are the same. Returning NA.") | |
return(NA) | |
} | |
} | |
}else{ | |
value<-atan(y/x) | |
if(x<0){ | |
value<-value+pi | |
} | |
} | |
return(value) | |
} | |
getNewPoint <- function(p1, p2, short){ | |
# verkürzen der Pfeile damit es "hübscher aussieht" | |
m <- getPolar(p1,p2) | |
if(is.na(m)){ | |
return(NA) | |
}else{ | |
r <- sqrt((p1$x - p2$x )^2 + (p1$y - p2$y)^2) | |
x <- p1$x + (r - short) * cos(m) | |
y <- p1$y + (r - short) * sin(m) | |
return (data.frame(x=x, y=y)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment