Dach: Mansarde (Giebel/Walm) ueber rechtwinkligen nicht-rechteckigen Grundrissen mit Knicklinie

This commit is contained in:
karim committed 2026-10-21 23:32:09 +02:00
1 parent 707944a045
commit c3f09d6a3a
3 files changed
+49 -6

No files matched your search

+13 -3
View File
@@ -338,7 +338,7 @@ const swapLine = (l: [Vec2, Vec2]): [Vec2, Vec2] => [swap2(l[0]), swap2(l[1])];
export function roofGeometry(roof: Roof, eavesZ: number): RoofGeometry {
// Walmdach über einem rechtwinkligen, nicht-rechteckigen Grundriss (L/T/U …):
// echte Flächen mit Graten und Kehlen statt Bounding-Box (s. roofSkeleton.ts).
if ((roof.shape === "walm" || roof.shape === "sattel") && isRectilinearNonRect(roof.outline)) {
if ((roof.shape === "walm" || roof.shape === "sattel" || (roof.shape === "mansarde" && roof.mansardType !== "zelt")) && isRectilinearNonRect(roof.outline)) {
return rectilinearWalm(roof, eavesZ);
}
if (roof.shape === "pult" && isRectilinearNonRect(roof.outline)) {
@@ -399,12 +399,22 @@ function rectilinearWalm(roof: Roof, eavesZ: number): RoofGeometry {
: oe,
);
const tan = Math.tan(Math.max(0, roof.pitchDeg) * DEG);
const sk = rectilinearHipRoof(eaves, tan, eavesZ, roof.shape === "sattel" ? roof.ridgeAxis : undefined);
const gabled = roof.shape === "sattel" || (roof.shape === "mansarde" && (roof.mansardType ?? "giebel") === "giebel");
const ridgeAxis = gabled ? roof.ridgeAxis : undefined;
let knee: { d: number; tanUp: number } | undefined;
if (roof.shape === "mansarde") {
// Knick bei `mansardKneeRatio` der maximalen Dachtiefe (Abstand First–Traufe).
const depth = rectilinearHipRoof(eaves, 1, 0, ridgeAxis).ridgeHeight;
const ratio = Math.min(0.49, Math.max(0.05, roof.mansardKneeRatio ?? 0.4));
const aUp = Math.max(0, roof.pitchUpperDeg ?? roof.pitchDeg / 2) * DEG;
knee = { d: depth * ratio, tanUp: Math.tan(aUp) };
}
const sk = rectilinearHipRoof(eaves, tan, eavesZ, ridgeAxis, knee);
return {
eaves,
ridges: sk.ridges,
hips: sk.hips,
breaks: [],
breaks: sk.breaks,
planes: sk.planes.map((pts) => ({ pts })),
gables: sk.gables,
ridgeHeight: sk.ridgeHeight,
+10
View File
@@ -83,3 +83,13 @@ describe("Pultdach auf L-Grundriss", () => {
expect(g.gables.length).toBe(3);
});
});
describe("Mansarde auf L-Grundriss", () => {
const roof = { id: "R", type: "roof", floorId: "eg", categoryCode: "31", outline: L, shape: "mansarde", mansardType: "giebel", pitchDeg: 45, pitchUpperDeg: 0, mansardKneeRatio: 0.4, overhang: 0, ridgeAxis: "x" } as unknown as Roof;
it("Flächen decken den Grundriss, oben flach auf Knickhöhe", () => {
const g = roofGeometry(roof, 0);
expect(g.planes.reduce((s, p) => s + planArea(p.pts), 0)).toBeCloseTo(11 * 4 + 8 * 2, 6);
expect(g.ridgeHeight).toBeCloseTo(1.2, 6); // Tiefe 3 · 0,4 · tan45
expect(g.breaks.length).toBeGreaterThan(0);
});
});
+26 -3
View File
@@ -122,6 +122,8 @@ export interface SkeletonRoof {
planes: Vec3[][];
ridges: [Vec2, Vec2][];
hips: [Vec2, Vec2][];
/** Knicklinien der Mansarde. */
breaks: [Vec2, Vec2][];
/** Senkrechte Giebelflächen (nur Satteldach, s. `ridgeAxis`). */
gables: Vec3[][];
ridgeHeight: number;
@@ -137,6 +139,8 @@ export function rectilinearHipRoof(
e: number,
/** Gesetzt → Satteldach: Kanten quer zu dieser Firstrichtung sind senkrechte Giebel (Ortgang). */
ridgeAxis?: "x" | "y",
/** Mansarde: ab Traufabstand `d` flacher (Steigung `tanUp`); Knicklinien landen in `breaks`. */
knee?: { d: number; tanUp: number },
): SkeletonRoof {
let eaves = cleanRing(eavesIn);
if (signedArea(eaves) < 0) eaves = [...eaves].reverse();
@@ -195,6 +199,7 @@ export function rectilinearHipRoof(
const lineKeys = new Set<string>();
const ridges: [Vec2, Vec2][] = [];
const hips: [Vec2, Vec2][] = [];
const breaks: [Vec2, Vec2][] = [];
let ridgeHeight = 0;
// Liegt die Strecke p–q auf einer Traufkante (Gerade UND innerhalb der Strecke)?
const onSeg = (k: number, p: Vec2) => {
@@ -220,9 +225,27 @@ export function rectilinearHipRoof(
for (const poly of face) {
const outer = cleanRing(poly[0].slice(0, -1).map(([x, y]) => ({ x: snap(x), y: snap(y) })));
if (outer.length < 3 || Math.abs(signedArea(outer)) < 1e-6) continue;
const z = (p: Vec2) => e + tan * Math.max(0, dist(k, p));
const z = (p: Vec2) => {
const d = Math.max(0, dist(k, p));
return knee ? e + tan * Math.min(d, knee.d) + knee.tanUp * Math.max(0, d - knee.d) : e + tan * d;
};
for (const piece of convexPieces(outer)) {
planes.push(piece.map((p) => [p.x, p.y, z(p)] as Vec3));
// Mansarde: Teilfläche an der Knicklinie (Traufabstand = knee.d) teilen.
const parts = knee
? [clipHalf(piece, (p) => knee.d - dist(k, p)), clipHalf(piece, (p) => dist(k, p) - knee.d)]
: [piece];
for (const part of parts) {
if (part.length < 3 || Math.abs(signedArea(part)) < 1e-9) continue;
planes.push(part.map((p) => [p.x, p.y, z(p)] as Vec3));
}
if (knee) {
const low = clipHalf(piece, (p) => knee.d - dist(k, p));
for (let i = 0; i < low.length; i++) {
const p = low[i];
const q = low[(i + 1) % low.length];
if (Math.abs(dist(k, p) - knee.d) < 1e-6 && Math.abs(dist(k, q) - knee.d) < 1e-6) breaks.push([p, q]);
}
}
}
// Grat-/Kehl-/Firstlinien: Flächenränder, die nicht auf der Traufe liegen.
for (let i = 0; i < outer.length; i++) {
@@ -265,7 +288,7 @@ export function rectilinearHipRoof(
];
gables.push(poly);
});
return { planes, ridges, hips, gables, ridgeHeight };
return { planes, ridges, hips, breaks, gables, ridgeHeight };
}
// ── Konvexe Zerlegung ───────────────────────────────────────────────────────