# Calculate height of rectangle in perspective

How can one calculate the height of a rectangle where the bottom part is unknown. The rectangle is in perspective, I know the top part and sides. However not the bottom.

Extra info: it's a picture taken of a paper, due to the angle of the camera the object is in perspective, top part being the furthest away and bottom part outside of the camera closest to you.

Situation like this: I know the green intersections, therefore the width in between and both sides (not the length obvious). Below is how I think it should be done, but it's not precise so I'm looking for people to help me determine if I'm doing something wrong or can improve it. #Paper size:
Pw=21.02cm
Ph=29,73cm

Calibration constant, number of pixels per cm at 50cm distance:
k = ### pixels/cm = (observed pixels calibrated)/Pw
kdist = 50cm

Q = k * Pw pixels width on the observed paper

Distance to top:
dtop = kdist*Q/Px

Px is the top width in pixels

We define a new point for measurement of the width, and define pixels to be perfect squares.
Py = 0.1 * Px (10% down)

New width for the new point, Py: is being manually measured for now.
Px2 calculated at Py.

Distance to Px2:
d2 = kdist*Q/Px2

Calculate height between top and Py:
h = sqrt(sqr(0.1*Pw)+sqr(dtop-d2))

Ratio between 0.1*Pw and full paper length:
r = Ph/h

Bottom line will be:
Y = r*Py

• What height do you mean? A rectangle is two dimensional, and lacks the dimension of height. A rectangle consists of two sets of equal sides, whose pairings parallel and opposite of each other. Perhaps I'm missing something here? – alxmke May 4 '14 at 13:19
• Are you attempting to calculate the side based on its perspective, or is it its absolute length? Specify, if you would. – alxmke May 4 '14 at 13:21
• Sorry maybe I wasn't specific. I'm trying to calculate the length from the top (green intersections) to the bottom (blue intersections). – Jafu May 4 '14 at 13:22
• Is it simply a rectangle, whose side lengths you are given three of, and need to find the remaining side's length? If so, please provide the lengths for each side of which you are aware. – alxmke May 4 '14 at 13:32
• I'm only aware of the top width, that is the length between left green to right green intersection. That's all. Then I know the sides too, but not the length of them. And then I'm trying to find where the bottom section is, which is outside the camera view. – Jafu May 4 '14 at 13:32  