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

Leave a Reply