Monthly Archives: May 2014

VPPS-SS14-W05 – LiDARgeil

Hausaufgabe – Funktion, die die Koordinaten eines Rechtecks berechnet:

calcCorners <- function(x.known, y.known,
orientation, declination,
size.x, size.y) {

orientation <- (orientation+declination)*pi/180

x <- sin(orientation)*size.x
y <- cos(orientation)*size.x

Cx=round(x,2)+x.known
Cy=round(y,2)+y.known

werteC <-data.frame(Cx,Cy)

Ax=round(x.known-cos(orientation)*size.y)
Ay=round(y.known+sin(orientation)*size.y)

werteA <- data.frame(Ax,Ay)

Bx=round(Ax+sin(orientation)*size.x,2)
By=round(Ay+ cos(orientation)*size.x,2)

werteB <-data.frame(Bx, By)

werte <- data.frame(werteA, werteB, werteC, x.known, y.known)
werte}

calcCorners(481054,5645540,9,1.6,30,48)

VPPS-SS14-W05-1-GISdur


 

 

Defining a function that transforms radian to degree since R calculates
with “rad”.

deg2rad<-function(alpha)(alpha*(pi/180))

Determine the function that calculates the length of the adjacent leg b
(Ankathete) and oposite leg a (Gegenkathete) of a right triangle given its
hypotenuse c and the angle alpha between the hypotenuse and the adjacent
leg .

triangle <- function(alpha, c) {
  a <- sin(deg2rad(alpha)) * c
  b <- cos(deg2rad(alpha)) * c

  values <- data.frame(x = round(a, 2), y = round(b, 2))

  return(values)
}

calcCorners is used for calculating the three missing corners from our plot
using the coordinates of the given corner, orientation (bearing from
north), declination (difference between magnetic and grid north, beeing in
this case -1.48°) and the two length of the plot.

calcCorners <- function(x.known, y.known, 
                        orientation, declination,
                        size.x, size.y) {
  alpha <- orientation - declination
  alpha270 <- alpha + 270
  alpha90 <- alpha + 90

  D2A <- triangle(alpha270, size.x)
  A2B <- triangle(alpha, size.y)
  B2C <- triangle(alpha90, size.x)

  Ax <- x.known + D2A[,1]
  Ay <- y.known + D2A[,2]
  Bx <- Ax + A2B[,1]
  By <- Ay + A2B[,2]
  Cx <- Bx + B2C[,1]
  Cy <- By + B2C[,2]
  Dx <- x.known
  Dy <- y.known
  Corners <- data.frame(A = list(x = Ax, y = Ay), 
                        B = list(x = Bx, y = By), 
                        C = list(x = Cx, y = Cy), 
                        D = list(x = x.known, y = y.known))
  return(Corners)

}

calcCorners with our values leads to the following results:

calcCorners(481054, 5645540, 9, 1.48, 48, 30)
##      A.x     A.y    B.x     B.y    C.x     C.y    D.x     D.y
## 1 481007 5645549 481012 5645578 481059 5645570 481054 5645540

 

Edit: Now we get a rectangle.