Loading Events

« All Events

  • This event has passed.

6 PM – Adv AI/ML – Darin

September 16 @ 6:00 pm - 7:00 pm

What we did today:

Sent an email when a detection happens using SMTP, and also began working with human pose estimation.

HW:

Calculating the Angle Between Three Points.

Your goal is to calculate the angle formed by three points:

A = (x1, y1)
B = (x2, y2)
C = (x3, y3)

We want to find angle ABC, so B is the center point.

Steps

  1. Create two vectors:

BA = A – B
BC = C – B

  1. Calculate cosine similarity:

cos(theta) = (BA · BC) / (|BA| × |BC|)

  1. Find the angle:

theta = arccos(cos(theta))

  1. Convert the result from radians to degrees.

Questions

Calculate angle ABC for each:

1.
A = (3, 0)
B = (0, 0)
C = (0, 4)

2.
A = (4, 0)
B = (0, 0)
C = (3, 4)

3.
A = (-4, 0)
B = (0, 0)
C = (4, 0)

For each problem, show:

  • BA
  • BC
  • Dot product
  • Length of BA
  • Length of BC
  • Cosine similarity
  • Final angle in degrees

Coding Task

Complete this Python function:

import numpy as np

def calc_angle(a, b, c):
    a = np.array(a)
    b = np.array(b)
    c = np.array(c)

    ba = ______
    bc = ______

    cosine_angle = __________________________

    angle = __________________

    return __________________

Test your function with:

print(calc_angle([3, 0], [0, 0], [0, 4]))

Your answer should be approximately 90 degrees.

Final goal: Be able to explain what each line of the calc_angle() function does and why point B must be the middle point.

NumPy Hints

You may find these functions useful:

np.dot(a, b)          # dot product of two vectors
np.linalg.norm(a)     # length/magnitude of a vector
np.arccos(x)          # inverse cosine (returns radians)
np.degrees(x)         # converts radians to degrees

Also remember:

ba = a - b
bc = c - b

Think about which NumPy function belongs in each blank of calc_angle().

Notes:

Contact me at ddjapri@ayclogic.com
Class notes can be found here

Details