Here's a function I use for creating masks at specific angles around a reference vector by comparing it with a vector from a reference point to get(position). The output is in degrees to make it easier to work with.
Reference point: e.g. the location of the render camera or the center of an object/planet
Reference vector: Line between 2 points or derived from the heading/altitude of an object/light e.g. the position of the sun.
To create a mask, just feed it into a colour adjust node and set the black and white levels to the required angles.
For example I'm currently using it to mask a spherical image map used for simulating city lights on the Earth. Reference point is the centre of the planet, reference vector is derived from the position of the sun (I negate it for simplicity). This allows the lights to be hidden on the daylight side as a mask and fading in the lights towards the night side of the planet by multiplying the mask with the luminance of the lights so that the lights start of dim and fade up to full intensity after 2-3 degrees.
Animation: The mask can be animated easily by duplicating the animation of the reference point/reference vector where applicable. This is easy when the camera is the reference point as you just need a get(camera position) node
I've also included a clip to convert Heading/Altitude to a vector... e.g. to convert the sun's position to a vector for use in the above clip. They're both the same functionally. The TGD shows the basic usage of both combined.