Executing the above code produces:
"sin values:" 0.0000 0.5000 0.7071 0.8660 1.0000 "cos values:" 1.0000 0.8660 0.7071 0.5000 0.0000 "tan values (note: 90 degrees is infinite):" 0.0000 0.5774 1.0000 1.7321 Inf
Using the arctangent function atan2(), you can calculate the polar angle of a point (x, y) on a plane:
Example
# Calculate the polar angle of point (1,1) (should be 45 degrees)
angle_rad <-atan2(1, 1)
angle_deg <- angle_rad *180/pi
print(paste("Angle of point (1,1):", angle_deg, "degrees"))
# Calculate the polar angle of point (-1, 1) (should be 135 degrees)
angle_rad <-atan2(1, -1)
angle_deg <- angle_rad *180/pi
print(paste("Angle of point (-1,1):", angle_deg, "degrees"))
Executing the above code produces:
"Angle of point (1,1): 45 degrees" "Angle of point (-1,1): 135 degrees"
YouTip
R Language Examples