Sin, Cos, Tan, and Pythagoras

Solving Problems Using Trigonometry and Coding.

You'll find a series of basic trigonometric problems below (finding angles and lengths of sides on right angle triangles). You can use one or more of three approaches to solving them:

Notes and Code Outcome

I. Find Hypothenuse Given an Angle and the Opposite Side Length.

Write a program that finds the hypothenuse of a triangle given the length of the opposite side and an angle.

Test Case:

  • angle (θ) = 30°
  • opposite side length = 10

Answer ▼

Hints

Do the algebra by hand and find the equation for h.

Python:

  • You'll need to import the numpy library (if you're not using Glowscript) with import numpy as np
  • to get the value of pi use np.pi
  • radians: most programming languages work in radians, not degrees.
  • to use a function like sin do x = np.sin(2).
For example, to find the sine of 90 degrees (i.e. sin(π/2))

                      import numpy as np
                      angle = np.pi/2  # 90 degrees
                      x = np.sin(angle)
                      print(x)
                    

Javascript:

  • in Javascript, pi is given by Math.PI
  • the trigonometric functions (Math.sin(), Math.cos(), Math.tan(), Math.asin(), etc.) in Javascript (and most programming languages) expects the angle to be in radians.

II. Find Hypothenuse Given an Angle and the Adjacent Side.

Write a program that finds the hypothenuse of a triangle given the length of the adjacent side and an angle.

Test Case:

  • angle (θ) = 40°
  • adjacent side length = 8

Answer ▼

III. Find Adjacent Side Given an Angle and the Hypothenuse

Write a program that finds the length of the adjacent side of a right-angle triangle given the angle and the length of the hypothenuse.

Test Case:

  • angle (θ) = 35°
  • hypothenuse (h) = 12

Answer ▼

IV. Find Angle Given Adjacent and Opposite Sides

Write a program that finds the angle (θ) given the lengths of the adjacent and opposite sides.

Test Case:

  • adjacent (a) = 15
  • opposite (o) = 12

Answer ▼

Hints

Python:

  • inverse trig functions uses the arc nomenclature np.arccos(), you may be more familar with the notation "cos-1()"
  • The inverse trig functions also work in radians.
Javascript:
  • inverse trig functions are Math.acos() ..., you may be more familar with the notation "cos-1()"
  • The inverse trig functions also work in radians.

V. Find Hypothenuse Given Two Sides

Write a program that finds the length of the hypothenuse of a right triangle given the length of the two other sides.

Test Case:

  • side a = 12
  • side b = 16

Answer ▼

Hints

  • squaring a number requires two stars: 32 is 3**2
  • the square root (√) is the same as raising a number to the ½ power: