Distance from point to line using $x \sin \theta - y \cos\theta$

I am struggling to understand an equation given in an academic paper (in atmospheric sciences/geography) that I am reading. The paper defines a line, called the Clear Line, which is derived through linear regression of a number of points. They state that

the transformation that quantifies the perpendicular displacement of a point from this line with be given by: $d = x \sin \theta - y \cos \theta$, where $\theta$ is the slope angle of the line.

I understand this to mean that the given equation should tell me the perpendicular distance from the point to the line. I have two problems: I can't see how this works, and it gives me different answers to other formulae that I do understand.

The diagram below shows a point (A) and two lines, $y = x$ and $y = x + 6$. Obviously the distance from the point (the dotted line) should be longer for $y = x + 6$ than it should be for $y = x$, but the formula given in the paper gives the same result for both. Of course this is the case, as the formula takes into account three of the four variables involved (gradient of the line and x and y locations of the point, but not the y-intercept of the line).

So, I have two questions:

1. Am I correct in stating that the formula given in the paper does not calculate the distance from the point to the line.

2. Given that it doesn't do that - what does it do? I assume it does something relevant (either that or the paper is completely wrong!) - but I can't seem to work out what it does by using trigonometry, constructing various triangles, and trying to understand where the equation came from - but I can't work it out!. It does seem to produce an answer that is vageuly related to the direction (if we just look at lines of different gradients - ignoring the intercepts - it seems to give a result which is related to the distance from the line).

Any ideas would be much appreciated!

-
What is your software for sketching the plots? – Ned Dabby Jan 5 '13 at 16:14
I used GeoGebra - see geogebra.org/cms – robintw Jan 5 '13 at 19:19

Distance of a point $(x_0,y_0)$ from a line $ax+by+c=0$ is $|ax_0+by_0+c|/\sqrt{a^2+b^2}$. You can write the equation of a line as $x\sin(\theta)-y\cos(\theta)+d=0$ where $\theta$ is angle with $x$ axis and $d$ is signed distance of origin from the line. Then distance of the point $P_0=(x_0,y_0)$ from the line will be $D_0=|x_0\sin(\theta)-y_0\cos(\theta)+d|$.

Edit 1:

Suppose you have the line $y=x+6$ and you want to write it in angle $\theta$ format.

a) Write this equation by bringing all terms to one side, as in $x-y+6=0$, now comparing with our blueprint $ax+by+c=0$ we have $a=1,b=-1,c=6$.

b) Find angle $\theta$ , in $[0,180)$ range, so that $\sin \theta=a/\sqrt{a^2+b^2}$. Here $\sin \theta=1/\sqrt{1^2+1^2}=1/\sqrt 2$. A calculator could be used to get $\theta$ but in this case we know from geometry $\theta=45^\circ$. In general $\theta=\sin^{-1} (a/\sqrt{a^2+b^2})$. Here $\sin^{-1}$ is a function that is available on most programs as $asin$ or $arcsin$ or $inv\ sin$, etc.

c) To get the $d$ in $x\sin(\theta)-y\cos(\theta)+d=0$ simply use $d=c/\sqrt{a^2+b^2}$. So to convert $x-y+6=0$ we divide the equation by $\sqrt{a^2+b^2}$, which is $\sqrt 2$ in our example, to get $1/\sqrt 2 \ x-1/\sqrt 2 \ y+6/\sqrt2=0$. Now comparing against $x\sin(\theta)-y\cos(\theta)+d=0$ we have $\sin \theta =1/\sqrt 2$, $\cos\theta=1/\sqrt 2$, and $d=6/\sqrt 2$. The meaning of $d$ here is the length of line segment that starts from origin and ends perpendicular to the original line $y=x+6$.

-
Thanks. Can you confirm what $d$ should be? Is it just the y-intercept? I have tried plotting the $x \sin \theta - y \cos \theta + d = 0$ for various values of $d$, and it seems to change the angle of the line, as well as the y-intercept of the line (and $d$ doesn't seem to be the y-intercept). Any ideas? – robintw Jan 4 '13 at 12:40
Here is another formulation you might find easier to use. If the equation of line is $y=mx+b$ then distance of $(x_0,y_0)$ from it will be $d=|y_0-mx_0-b|/\sqrt{1+m^2}$. For example the distance of the point $(9,3)$ from the line $y=x+6$ is $d=|3-1*9-6|/\sqrt{1+1^2}=12/\sqrt{2}=6\sqrt{2}$, which agrees with your picture. – Maesumi Jan 4 '13 at 23:15
Thanks for the other formulation. You're right, I do understand that more, but unfortunately I need to understand the other formulation too - as the paper I am basing some of my work on uses it, and I need to understand the consequences of them not having the $+ d$ on the end of their equation. I can see that the line $y =x$ can be represented as $x \sin \theta - y \cos \theta = 0$, but I can't see how the $+ d$ bit works. It doesn't seem to behave like the y-intercept - so how, for example, should I represent $y = x + 6$ in the $\sin$ and $\cos$ formulation? – robintw Jan 5 '13 at 17:21
Their equation is not standard/correct. An equation means equality of two quantities. If they are dropping one side it is probably because they assume it is known implicitly. But it is not clear to me what they mean. In my first answer $d$ is the perpendicular distance of origin from the given line (it is not $y$ or $x$ intercept). If there is no such thing in their paper then it likely means their line or main line is going through origin and hence $d=0$, as in your line $y=x$. In my comment $d$ is the distance of $(x_0,y_0)$ from the line. I'll edit my answer to add an example. – Maesumi Jan 6 '13 at 0:23

The equation in the paper correctly gives the distance between a point and a line, but only when the line goes through the origin. For other lines the trick is to shift both the line and the point up or down the same amount until the line goes through the origin. If the line intercepts the y axis at b the resulting equation is $d=x \sin(\theta)-(y-b)\cdot \cos(\theta),$ where $(x,y)$ is the point, $\theta$ is the angle the line makes with the $x$ axis, and $d$ is the distance between the point and the line.

-