Wrote function to calculate angles