TactivergeLite

Lite / Building Machines That Respond / Week 29

Angles in, positions out (and back again)

A camera must point at a target 10 cm away and 4 cm up. What angle do you send the tilt servo, and will your code even understand 'degrees'?

About 35 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

Robots work in both directions: from a joint angle to where the hand is, and from where a target is to the angle needed. And robot software almost always measures angles in radians, so a missing conversion can swing an arm the wrong way.

Predict

A 20 cm link points 60° above horizontal. How far does its tip reach horizontally?

  1. 10 cm
  2. 17.3 cm
  3. 20 cm
Guess first, then reveal

10 cm. Horizontal = L cos θ = 20 × cos 60° = 20 × 0.5 = 10 cm. The vertical part is the bigger one at this steep angle: 20 × sin 60° ≈ 17.3 cm.

Discover

Open the kinematics lab. Set the elbow joint straight so the arm acts like one long link, then try shoulder angles of 30°, 60°, 90° and 120°. For each, predict x = L cos θ and y = L sin θ before reading the tip position. What happens to x past 90°?

What the interactive shows (text version)

The kinematics lab shows a two-joint arm with sliders for each joint angle and a readout of the tip's x and y position. With the elbow straight it behaves like one link of the combined length: at 30°, 60°, 90° and 120° the tip's x equals length × cos θ and y equals length × sin θ, and x becomes negative past 90°.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: Listen for how to pick which ratio to use from the two sides you know.

A calm first walk through SOH CAH TOA: which sides are opposite, adjacent and the hypotenuse, and how the ratios are formed.

“Basic trigonometry | Basic trigonometry | Trigonometry | Khan Academy” by Khan Academy (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

Understand

Past 90°, cos goes negative

Measure the angle from the positive x-axis. Between 90° and 180° the link points backwards, so its horizontal part is negative: cos 120° = −0.5. The vertical part stays positive: sin 120° ≈ 0.866. A robot's code doesn't need special cases: the signs of sin and cos tell it which way the link points.

Working backwards: inverse functions

If you know two sides and want the angle, use an inverse: θ = tan⁻¹(opposite ÷ adjacent), sin⁻¹(opposite ÷ hypotenuse) or cos⁻¹(adjacent ÷ hypotenuse). For a target 10 cm across and 4 cm up, θ = tan⁻¹(0.4) ≈ 21.8°. In code, atan2(y, x) does this and also gets the quadrant right.

Radians: the unit code uses

A radian is the angle where the arc length equals the radius. A full turn is 2π rad = 360°, so degrees × π/180 = radians. 90° ≈ 1.571 rad, and 1 rad ≈ 57.3°. Python's math.sin(30) treats 30 as radians and returns about −0.988, not 0.5. Convert with math.radians first.

Explain it another way

Intuitive

Degrees chop a circle into 360 slices because people liked the number. Radians measure the angle by how much of the radius you'd walk around the edge, which is why maths and code prefer them.

Technical

Components: x = L cos θ, y = L sin θ for θ ∈ [0, 2π). Inverse: θ = atan2(y, x) ∈ (−π, π]. Conversion: θ_rad = θ_deg · π/180.

Mathematical

Target (10, 4) cm: θ = tan⁻¹(4/10) ≈ 21.8° ≈ 0.381 rad, distance √116 ≈ 10.8 cm. 1.5 rad = 1.5 × 180/π ≈ 85.9°.

Applied

Servo libraries often take degrees while maths libraries take radians. Teams label every angle variable with its unit (theta_deg, theta_rad) to stop a conversion bug reaching the robot.

Worked example 1

A 25 cm link at 150°: where is its tip?

x = 25 cos 150° ≈ 25 × (−0.866) ≈ −21.7 cm (behind the joint); y = 25 sin 150° = 25 × 0.5 = 12.5 cm.

Worked example 2

A ramp must rise 30 cm over 120 cm. At what angle?

tan θ = 30 ÷ 120 = 0.25, so θ = tan⁻¹(0.25) ≈ 14.0°.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

cm

°

rad

rad

Practice 5. A learner writes math.sin(30) in Python to get the height of a link at 30° and gets about −0.988. Why?

Apply it

A pan-tilt camera on a rover must look at three targets: (10, 4) cm, (5, 5) cm and (−6, 8) cm relative to its pivot. Find each tilt angle in degrees and in radians, and say which target needs atan2 rather than tan⁻¹ to get the right answer.

Reflect

Name one bug that would appear if a robot's code mixed up degrees and radians. How would you notice it in a test?

Write your answer on paper or in your own notes. Lite never stores what you write.

← sin, cos and tan are just ratiosFind the fingertip: two links, one answer →