Monthly Archives: May 2014

VPPS-SS14-W05-1-Supernasen



# calculates the x and y coordinates of the missing corner points of a
# rectangle based on the given coordinates of one corner point
# 
# Args: x.known: the x-coordinate of the given corner point y.known: the
# y-coordinate of the given corner point orientation: bearing from
# magnetic north decliantion: difference between magnetic north and grid
# north size.x: the length of the rectangle border in x-direction size.y:
# the length of the rectangle border in y-direction
calcCorners <- function(x.known, y.known, orientation, declination, size.x, 
    size.y) {

    calculateTriangle <- function(alpha, c) {
        alphaRad <- alpha * pi/180
        a <- sin(alphaRad) * c
        b <- cos(alphaRad) * c
        result <- data.frame(x = round(a, 2), y = round(b, 2))
        return(result)
    }

    alpha <- orientation + declination
    alpha2 <- alpha + 90
    alpha3 <- alpha + 270
    distAB <- calculateTriangle(alpha, size.y)
    distAD <- calculateTriangle(alpha, size.x)
    distBC <- calculateTriangle(alpha2, size.x)
    distDC <- calculateTriangle(alpha3, size.y)
    A <- (c(x.known, y.known))
    B <- (c(y.known + distAB, x.known))
    D <- (c(x.known + distAD, y.known))
    C <- (c(B[1] + distBC, D[1] + distDC))
    Corners <- (c(A, B, C, D))
    Corners
}

# example of function usage
calcCorners(481054, 5645540, 6, 1.48, 48, 30)
## [[1]]
## [1] 481054
## 
## [[2]]
## [1] 5645540
## 
## $x
## [1] 5645544
## 
## $y
## [1] 5645570
## 
## [[5]]
## [1] 481054
## 
## $x
## [1] 5645592
## 
## $y
## [1] 5645538
## 
## $x
## [1] 481031
## 
## $y
## [1] 481064
## 
## $x
## [1] 481060
## 
## $y
## [1] 481102
## 
## [[12]]
## [1] 5645540

VPPS-SS14-W05-1-TimsStruppis




# Definieren eine Funktion die Grad in Radianten umwandelt
degToRad <- function(alpha) {
    alpha * pi/180
}

# Definieren Funktion die uns An- und Gegenkathete ausgibt
hypoAlphaToGegenAn <- function(c, alpha) {
    a <- sin(degToRad(alpha)) * c
    b <- cos(degToRad(alpha)) * c
    result <- data.frame(x = round(a, 2), y = round(b, 2))
    return(result)
}

# calcCorners is a function, which will give you the UTM- coordinates for
# every corner of a plot (rectangle) D is the name of known point
# (x.known, y.know)

calcCorners <- function(x.known, y.known, orientation, declination, size.x, 
    size.y) {
    # calculate all angles of plot
    alphaA <- orientation + declination
    alphaB <- alphaA + 90
    alphaC <- alphaB + 90
    alphaD <- alphaC + 90
    angle <- list(alphaA = alphaA, alphaB = alphaB, alphaC = alphaC, alphaD = alphaD)

    # Calculate distance of corners in coordinates along South-North,
    # East-West axis

    AtoB <- hypoAlphaToGegenAn(size.x, alphaA)
    BtoC <- hypoAlphaToGegenAn(size.y, alphaB)
    CtoD <- hypoAlphaToGegenAn(size.x, alphaC)
    DtoA <- hypoAlphaToGegenAn(size.y, alphaD)


    # add distances to given values to recive UTM-Coordinates for every coner
    # of the plot

    AxValue <- x.known + DtoA[1, 1]
    AyValue <- y.known + DtoA[1, 2]
    BxValue <- AxValue + AtoB[1, 1]
    ByValue <- AyValue + AtoB[1, 2]
    CxValue <- BxValue + BtoC[1, 1]
    CyValue <- ByValue + BtoC[1, 2]
    DxValue <- x.known
    Dyvalue <- y.known
    Corners <- data.frame(A = list(x = AxValue, y = AyValue), B = list(x = BxValue, 
        y = ByValue), C = list(x = CxValue, y = CyValue), D = list(x = x.known, 
        y = y.known))
    return(Corners)

}

# Calculate UTM-coordinates for specific plot

calcCorners(481054, 5645540, 6, 2, 48, 30)
##      A.x     A.y    B.x     B.y    C.x     C.y    D.x     D.y
## 1 481024 5645544 481031 5645592 481061 5645588 481054 5645540