From ebf2a39704f96a04b857dd14e534a7850f0bb224 Mon Sep 17 00:00:00 2001
From: Elod Csirmaz
Date: Sun, 8 Dec 2024 00:43:46 +0000
Subject: [PATCH] Add scaling to height maps
---
polyhedron.html | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/polyhedron.html b/polyhedron.html
index d9b19a5..87eb1a3 100644
--- a/polyhedron.html
+++ b/polyhedron.html
@@ -142,13 +142,15 @@ Nonplanar faces will be triangulated by OpenSCAD.
return cls(points=point_list, faces=faces, convexity=convexity)
@classmethod
- def from_heightmap(cls, heights: List[List[float]], base: float = 0., convexity: int = 10):
+ def from_heightmap(cls, heights: List[List[float]], base: float = 0., step_x: float = 1., step_y: float = 1., convexity: int = 10):
"""Construct a polyhedron from a 2D matrix of heights. If the height at [0,0] is Z, it maps
to the point (0, 0, Z).
Arguments:
- heights: The 2D matrix of heights
- base: The height at which the base will be - in the scale of heights (optional; default 0)
+ - step_x: The X coordinate becomes `step_x * index_x` (default 1)
+ - step_y: The Y coordinate becomes `step_y * index_y` (default 1)
- convexity: see OpenSCAD
"""
rows = len(heights)
@@ -158,8 +160,8 @@ Nonplanar faces will be triangulated by OpenSCAD.
bottom_point_map = {}
for row_ix, row in enumerate(heights):
for col_ix, height in enumerate(row):
- point = Point([row_ix, col_ix, height])
- bottom_point = Point([row_ix, col_ix, base])
+ point = Point([row_ix*step_x, col_ix*step_y, height])
+ bottom_point = Point([row_ix*step_x, col_ix*step_y, base])
point_map[(row_ix, col_ix)] = len(point_list)
point_list.append(point)
@@ -291,7 +293,7 @@ Nonplanar faces will be triangulated by OpenSCAD.
Static methods
-def from_heightmap(heights: List[List[float]], base: float = 0.0, convexity: int = 10)
+def from_heightmap(heights: List[List[float]],
base: float = 0.0,
step_x: float = 1.0,
step_y: float = 1.0,
convexity: int = 10)
-
Construct a polyhedron from a 2D matrix of heights. If the height at [0,0] is Z, it maps
@@ -300,6 +302,8 @@ to the point (0, 0, Z).
- heights: The 2D matrix of heights
- base: The height at which the base will be - in the scale of heights (optional; default 0)
+- step_x: The X coordinate becomes
step_x * index_x
(default 1)
+- step_y: The Y coordinate becomes
step_y * index_y
(default 1)
- convexity: see OpenSCAD