tested and corrected triangle formula