Challenge - 5 Problems
Coordinate Systems Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of coordinate transformation using base R
What is the output of this R code that converts Cartesian coordinates (x, y) to polar coordinates (r, theta)?
R Programming
cartesian_to_polar <- function(x, y) {
r <- sqrt(x^2 + y^2)
theta <- atan2(y, x)
return(c(r = r, theta = theta))
}
result <- cartesian_to_polar(3, 4)
print(round(result, 2))Attempts:
2 left
💡 Hint
Recall that r is the distance from origin and theta is the angle in radians from the x-axis.
✗ Incorrect
The distance r is sqrt(3^2 + 4^2) = 5. The angle theta is atan2(4, 3) ≈ 0.93 radians.
🧠 Conceptual
intermediate1:30remaining
Understanding coordinate system origin shifts
If you shift the origin of a 2D Cartesian coordinate system by vector (2, -3), what are the new coordinates of point (5, 7)?
Attempts:
2 left
💡 Hint
Subtract the shift vector from the original point coordinates.
✗ Incorrect
Shifting the origin by (2, -3) places the new origin at old (2, -3). New coordinates = (5 - 2, 7 - (-3)) = (3, 10).
🔧 Debug
advanced2:00remaining
Identify the error in coordinate rotation code
What error does this R code produce when rotating a point (x, y) by angle theta (in radians)?
R Programming
rotate_point <- function(x, y, theta) {
x_new <- x * cos(theta) - y * sin(theta)
y_new <- x * sin(theta) + y * cos(theta)
return(c(x_new, y_new))
}
rotate_point(1, 0, pi / 2)Attempts:
2 left
💡 Hint
Check if all variables are defined and used correctly.
✗ Incorrect
The function correctly computes the rotated coordinates. Rotating (1,0) by 90 degrees (pi/2 radians) results in (0,1).
📝 Syntax
advanced1:30remaining
Syntax error in coordinate transformation function
Which option contains the correct syntax for defining a function that converts polar to Cartesian coordinates in R?
Attempts:
2 left
💡 Hint
Check the return statement syntax and how multiple values are returned.
✗ Incorrect
Option A uses return() with a named vector correctly. Option A returns unnamed vector but is syntactically valid. Option A tries to return two values separately which is invalid. Option A returns vector without return() but is valid in R as last expression is returned.
🚀 Application
expert3:00remaining
Calculate distance between two points in different coordinate systems
Given point A in Cartesian coordinates (3, 4) and point B in polar coordinates (r = 5, theta = pi/3), what is the Euclidean distance between A and B?
Attempts:
2 left
💡 Hint
Convert point B to Cartesian coordinates first, then use distance formula.
✗ Incorrect
Point B in Cartesian: x = 5*cos(pi/3) = 2.5, y = 5*sin(pi/3) ≈ 4.33. Distance = sqrt((3-2.5)^2 + (4-4.33)^2) ≈ sqrt(0.25 + 0.11) ≈ 0.6.