Understanding SIFT descriptor calculation

I need to understand how SIFT calculates the descriptors for the keypoints.

Intuitively, i understand that it takes each keypoint, calculates the gradients for each pixel in a circular neighborhood of the keypoint.
The paper mentions a coordination system rotation in the keypoint.

My questions:

  1. is my intuitive understanding correct?
  2. im following this implementation of SIFT, and in the part of the calculation function there is this cos/sin calculation:
    OpenCV's SIFT implementation · GitHub
    i think this is related to the coord system rotation, can you explain how?

p.s. This is my first post here!