Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i had a geometry/trignometry problem come up at work today, and i've been out of school too long: i've lost my tools.

i'm starting with a rectangle of known width (w) and height (h). For graphical simplification i can convert it into a right-angle triangle:

alt text

i'm trying to find the coordinates of that point above which is perpendicular to the origin:

alt text

i've labelled the opposite angle t1 (i.e. theta1, but Microsoft Paint cannot easily do greek and subscripts), and i deduce that the two triangles are similar (i.e. they have the same shape):

alt text

Now we come to my problem. Given w and h, find x and y.

Now things get very difficult to keep drawing graphically, to explain my attempts so far.

But if i call the length of the line segment common to both triangles M:

alt text


M = w∙sin(t1)

Now i can focus on the other triangle, which i'll call O-x-M:

alt text

and use trig to break it down, giving:

x = M∙sin(t1)
  = w∙sin(t1)∙sin(t1)

y = M∙cos(t1)
  = w∙sin(t1)∙cos(t1)


t1 = atan(h/w)

Now this all works (i think, i've not actually tested it yet), and i'll be giving it to a computer, so speed isn't horribly important.

But my god, there must have been an easier way to get there. i feel like i'm missing something.

By the way, what this will be used for is drawing a linear gradient in along that perpendicular:

alt text

share|cite|improve this question
I think your approach is very straightforward ... it's certainly correct! If you're concerned that your final formulas look overly-complicated, it's because you stopped too soon. To finish up, you should eliminate the references to $t_1$. If you happen to know how to simplify "the sine (or cosine) of the arctan of $t_1$", great. If not, you may notice that the sine and cosine appear in your picture. Writing $s$ for the length of the hypotenuse, you have $\sin t_1 = h/s$ and $\cos t_1 = w/s$. Thus, your formulas reduce to $x=w h^2/s^2$ and $y=hw^2/s^2$. Then, since $s^2 = x^2 + y^2$ ... – Blue Jan 19 '11 at 11:49
Re: Eliminating $t_1$ ... Notice that, with your formulas, you'd compute $t_1$ via an inverse-trig function, only to toss the result into trig functions. Inverse-trigs turn "length info" into "angle info", while trigs turn "angle info" into "length info". Your solution passes through "angle info" on a journey from "length info" back to "length info". When this happens, it's a good bet that there's an algebraic expression that makes the journey directly. Here, you should suspect that $\cos {\rm atan} h/w$ is expressible algebraically in terms of $h/w$; and it is: $1/\sqrt{1+(h/w)^2}$ (or $w/s$) – Blue Jan 19 '11 at 12:18
It might looks more straightforward because i've already traveled the route, but it took me 45 minutes to get there. While i was getting there i thought, this can't be right, there has to be a better way. i had to find the size of a 3rd implied triangle, based on the similarity of two previous triangles. And sin(cos(atan)), "Oh boy, this is getting nasty." – Ian Boyd Jan 19 '11 at 12:49
up vote 4 down vote accepted

An equation for the hypotenuse of the right triangle is $y=-\frac{h}{w}x+h$. Its slope is $-\frac{h}{w}$ (change in $y$-coordinate over change in $x$-coordinate). The slope of any line perpendicular to the hypotenuse is $\frac{w}{h}$ (perpendicular lines have slopes with product $-1$, or it is sometimes said that the slope of a perpendicular line is the "opposite reciprocal"), so an equation for the line through the origin and perpendicular to the hypotenuse is $y=\frac{w}{h}x$. The point you want is the solution to the system of equations: $$\begin{align}y&=-\frac{h}{w}x+h\\y&=\frac{w}{h}x\end{align}$$

These equations give two expressions that are both equal to $y$, so set them equal: $$-\frac{h}{w}x+h=\frac{w}{h}x$$ and solve:$$h=\left(\frac{w}{h}+\frac{h}{w}\right)x=\frac{w^2+h^2}{wh}x$$ $$x=\frac{h^2w}{w^2+h^2}$$ Use one of the original equations to find $y$: $$y=\frac{w}{h}x=\frac{hw^2}{w^2+h^2}$$

edit Working from Hans Lundmark's answer, final method, a vector from the origin to the desired point is in the same direction as $\langle\frac{1}{w},\frac{1}{h}\rangle$ or equivalently $\langle h,w\rangle$. The distance from the origin to the desired point is the length of the altitude—call this $d$. Looking at the area of the triangle, it is both $\frac{1}{2}wh$ and $\frac{1}{2}d\sqrt{w^2+h^2}$, so $d=\frac{wh}{\sqrt{w^2+h^2}}$. The desired vector is thus $$\begin{align} \frac{\langle h,w\rangle}{|\langle h,w\rangle|}d &=\frac{\langle h,w\rangle}{\sqrt{w^2+h^2}}\frac{wh}{\sqrt{w^2+h^2}} \\ &=\frac{\langle h,w\rangle wh}{w^2+h^2} \\ &=\left\langle\frac{h^2w}{w^2+h^2},\frac{w^2h}{w^2+h^2}\right\rangle .\end{align}$$

share|cite|improve this answer
I just want to make a plug for the "intercept-intercept form" of the line equation: $\frac{x}{w}+\frac{y}{h}=1$ :) – Blue Jan 19 '11 at 11:38
Of the two answers that provide final form, this is the one i understand more :) Accepted. – Ian Boyd Jan 19 '11 at 14:16

Parametrize the line from $(w,0)$ to $(0,h)$ by $(w,0) + t(-w, h)$. Then you are searching for the point $(x,y)$ on the line such that $(x,y)\cdot (-w,h) = 0$.

share|cite|improve this answer
Is the "*" in the final equation intended to be dot-product? – Isaac Jan 19 '11 at 1:58
Yes, that is the dot product. – M.B. Jan 19 '11 at 15:12
I've edited your answer to render the ordered pairs, expression, and equation using $\LaTeX$. Feel free to re-edit or revert if you don't like the result. – Isaac Jan 19 '11 at 21:18

Another way: You have identified some angles as being equal in your last figure. This implies that several of the right triangles in the picture are similar. For example, $$ \frac{h}{w} = \frac{x}{y} = \frac{y}{w-x},$$ from which it is not too difficult to solve for $x$ and $y$.

And yet another: The hypotenuse lies on the line with equation $x/w+y/h=1$ (since the two points $(x,y)=(w,0)$ and $(x,y)=(0,h)$ satisfy this equation, and two points uniquely determine a line). The normal vector to a line can be read off from the coefficients of $x$ and $y$; it is $\mathbf{n}=(1/w,1/h)$ in this case. The point that you seek (let me call it $(a,b)$ here) lies on the line which goes from the origin in the direction that $\mathbf{n}$ points, so the point must be of the form $(a,b)=t \mathbf{n} = (t/w,t/h)$ for some number $t$. Substituting $(x,y)=(t/w,t/h)$ into the equation for the hypotenuse gives $t(1/w^2+1/h^2)=1$, from which we immediately find $t$ and hence also $$(a,b)=\left( \frac{1/w}{1/w^2+1/h^2}, \frac{1/h}{1/w^2+1/h^2} \right).$$

share|cite|improve this answer

Suppose $h = (h_1,h_2)$ and $w = (w_1, w_2)$. Then you know the slope of the line. Let's call this $m_1$. You also know that the line perpendicular to the point $(x,y)$ has slope $-\frac{1}{m_1}$. You get a system of equations.

share|cite|improve this answer

For fun, here's another approach ...

The area of your triangle is given by $\frac{1}{2} w h$, but it's also given by $\frac{1}{2}s m$, where $s$ is the length of the hypotenuse and $m$ is the length of your segment $M$. (To see why, flip the triangle over so that it's sitting on its hypotenuse; then, clearly, $s$ is the "base" and $m$ the "height".) Therefore,

$$w h = s m$$

Writing $\theta$ for the angle that segment $M$ makes with the horizontal, we have that

$$x = m \cos\theta = \frac{wh}{s}\cos\theta \hspace{0.5in} y = m\sin\theta = \frac{wh}{s}\sin\theta$$

By similar triangles, $\theta$ is also the angle in the top corner of your triangle, so

$$\cos\theta = \frac{h}{s} \hspace{0.5in} \sin\theta = \frac{w}{s}$$

and we have

$$x = \frac{wh^2}{s^2}=\frac{w h^2}{w^2+h^2} \hspace{0.5in} y = \frac{w^2 h}{s^2}=\frac{w^2h}{w^2+h^2}$$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.