theta is a degree measured in radians. As for the second question, it knows because of the trigonometric functions. Not sure how else to explain it, if you know what the trig functions actually mean it makes sense.