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


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))


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))


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.

One thought on “VPPS-SS14-W05-1-GISdur

  1. Tim Appelhans

    Well, if you don’t get a rectangle, I guess there is some bug in your code. Make sure to carefully check whether each step is doing what it should be doing.
    To avoid mistakes, you should use the functions that you’ve already written and tested as part of this function.

    I.e. use the functions ‘deg.to.rad()’ and ‘triangle()’ where appropriate inside ‘calcCorners()’ to avoid possible mistakes due to code repetition. Also, please make sure you use a consistent function naming scheme (lowerCanmelCase).

    Also, please revisit the definition of declination again to make sure your calculations are correct.

    All of the above should help debugging your code and lead you to the correct result.


Leave a Reply