# Generate Roof from a 2D Polygon

Let's say we have a 2D Polygon ( it can be concaved or convex), and on top of this polygon we are required to build a house roof. What is the algorithm that one can use for this?

The conditions:

1. The roof cannot be $0^o$ or $90^o$.
2. The created roof piece must be as smooth as possible ( smooth is defined as first order differentiable), meaning the slope of the roof must not change unnecessarily.

I'm sorry if the conditions sound vague. If you get lost, just think about this: you have a house, how do you generate the roof profile?

Note: The roof plan must be uniformly sloping, so no circle, or bump can be used.

-
Is the polygon the "floor plan" of the house? – Blue Jan 5 '11 at 4:25
@Day, you can say that – Graviton Jan 5 '11 at 4:29
How about drawing a circle around the polygon, building a hemispherical dome over it, then slicing off the parts of the dome that extend beyond polygon? – Blue Jan 5 '11 at 4:35
@Day, no, that's not what I have in mind :) – Graviton Jan 5 '11 at 5:48
@Ngu: What additional characteristics is the roof to have? Maybe that it's the same height along the perimeter of the polygon? Have you looked at "bump functions"? en.wikipedia.org/wiki/Bump_function – Blue Jan 5 '11 at 7:25

Here is an image I happen to have prepared for a book. It shows the medial-axis polyhedron over a convex polygon, which coincides with the straight skeleton as in lhf's answer, and also with the offset-procedure in alQpr's answer. Sides slope at $45^\circ$.

-
That's the graph of the distance to the polygon's boundary. – whuber Jan 6 '11 at 0:00
yup!! This is what I want. You have an algorithm for this? – Graviton Jan 6 '11 at 1:18
Sorry I never replied---Somehow I missed these comments. @whuber: Yes, precisely. – Joseph O'Rourke Nov 22 '11 at 22:11
@Graviton: The algorithm is described in Discrete and Computational Geometry, Chapter 5. – Joseph O'Rourke Nov 22 '11 at 22:11

Start at the outside. Step inwards a small amount to generate a first level (polygonal) curve at a small height above the wall. Project "ridge" lines from outward corners of house (or crotch lines for inside corners) through corresponding corners of the new polygon (I guess they'll be bisecting the angles of the original polygon) and whenever two or more ridgelines, or two or more of the edges meet, repeat the process starting with the reduced polygon(s) which give the level curve through the point of intersection.

-