Finding the sides of a rectangle inscribed in a right triangle given an aspect ratio Everything I have found on google/se has been about finding a maximum area rectangle, regardless of aspect ratio. 
I am trying to inscribe a rectangle inside of a right triangle. I do not know the width or height of the rectangle, but I know the aspect ratio. 
My hunch is that I need to find where w^2 + h^2 of my rectangle match the distance from the corner to the hypotenuse of my bounding triangle. Unfortunately I have forgotten a majority of the geometry I took in high school and can't figure out how I would do this, and my efforts to find a solution on Google have yielded mostly just maximum-area solutions without the fixed aspect-ratio constraint I have. 
I have posted a related question on SO that goes in to more detail of what I am trying to do:
https://stackoverflow.com/questions/33509077/dynamic-resize-image-to-different-sizes-with-paperclip-based-on-aspect-ratio
 A: Let the aspect ration be $m$.  Put the triangle in the coordinate plane with the right angle at the origin and the legs along the coordinate axes.  Take the line $y=mx$ and extend it until it hits the hypotenuse.  That gives you a diagonal for your rectangle.
Note:  if, instead of an explicit aspect ratio you just have a rectangle in the right ratio (but the wrong scale) then place your rectangle in the same coordinate plane, with one corner at the origin and sides aligned with the coordinate axes.  Then the diagonal for that rectangle is the line you want.
A: Let's say the vertices of the right triangle are at the origin, on the $x$-axis at $x=a$, and on the $y$ axis at $y=b$.  The hypotenuse has the equation $y = -\frac{b}{a}x + b.$  This describes a right triangle with sides $a,b,\sqrt{a^2+b^2}$ in the first quadrant.
Then, one diagonal of your inscribed rectangle will be $y = mx$.
Edit:  To clarify, $m$ is the slope of the line that defines what will be the diagonal of the rectangle.  If $0<m<1$ the rectangle is wider than it is tall; if $m=1$ it's a square; if $m>1$ it's taller than it is wide.  The aspect ratio of the right triangle, similarly, is $b/a$.  If $a=b$ it's an isosceles right triangle.  
You can solve these two equations for $x$ and $y$, which will be the two sides of your inscribed rectangle in terms of $a,b,m$:
$$x = \frac{ba}{ma+b};$$
$$y = \frac{mba}{ma+b}.$$
Depending on which side you chose to be $a$ and which you chose to be $b$, this may or may not give the larger area, so try both (or see if you can understand which one will give you the bigger value).
