Part 1 - Distance
Trigonometry is, unsurprisingly, the study of triangles. A triangle is defined by any three points in space not on a line and, despite its seeming simplicity, can lead to a lot of pain.
The most useful triangles, at least for our purposes, are right triangles - figures in which one angle is permanently set at 90 degrees. Given that Construct operates in a predefined 2d plane, a little trigonometry can go a long way towards helping objects relate to each other.
One important application of trigonometry is finding the distance between two arbitrary points: by drawing a right triangle whose hypotenuse (the longest arm of a right triangle) is defined by the two points you want to learn the distance between, you can deduce the length of this line with the formula
c^2 = a^2 * b^2
or, to refine it for our use:
dist = sqrt((x2-x1)^2 + (y2-y1)^2).
<img src="http://dl.dropbox.com/u/9498285/dist.png">
Fortunately, Construct's developers have included a system expression to do exactly this for us:
distance(x1,y1,x2,y2)
See Pyth.cap for a demonstration.
Part 2 - Sines and Cosines
First, a verbal mnemonic device:
SOH-CAH-TOA.
It stands for:
Sine = Opposite / Hypotenuse
Cosine = Adjacent / Hypotenuse
Tangent = Opposite / Adjacent
These values (sin, cos and tan, although we won't be using tan today) represent the length ratios of the arms listed above. No matter how large the triangle is, the sine of x degrees is the sine of x degrees, and so on.
Observe the following diagram of unknown angle Theta:
<img src="http://dl.dropbox.com/u/9498285/theta.png">
Notice that the hypotenuse of our imaginary triangle connects the two points (X1,Y1) and (X2,Y2). We construct this triangle anchored on the X axis because angles in Construct are measured in degrees from that point. This effectively makes the X axis our Adjacent arm (because it is adjacent to angle Theta), and the Y axis our Opposite (because ditto).
Since both Sine and Cosine rely on the value of the hypotenuse, the only remaining choice when calculating offset is which arm to use, and once we anchor our triangle properly it becomes clear - the Cosine value, because it is calculated with the Adjacent arm (which we've ascertained is the same as the X component) becomes our X offset modifier, and the Sine value (Opposite arm, parallel and equal to the Y component) becomes our Y offset modifier.
Because these values are always between -1 and 1, they'll need to be multiplied by another number, which we'll call Magnitude, to get more than ~1 pixel away from the object at the origin of our system.