Hi,

Guest

SL

Steve Lelievre

Wed, Feb 14, 2024 5:47 PM

Hi everyone,

I am using OpenSCAD to generate a 2-dimensional vector that I wish to

treat as a heightmap. If I had the data in a file, I could load it using

'surface' and to produce exactly what I want, because surface fills in

the areas between the height points to produce a continuous form.

How do I do the same thing directly from my vector?

I feel that there must be a way but today I am not seeing it, short of

processing the vector to construct a polyhedron ... surely there must be

an easier way?

Thanks,

Steve

Hi everyone,
I am using OpenSCAD to generate a 2-dimensional vector that I wish to
treat as a heightmap. If I had the data in a file, I could load it using
'surface' and to produce exactly what I want, because surface fills in
the areas between the height points to produce a continuous form.
How do I do the same thing directly from my vector?
I feel that there must be a way but today I am not seeing it, short of
processing the vector to construct a polyhedron ... surely there must be
an easier way?
Thanks,
Steve

JB

Jordan Brown

Wed, Feb 14, 2024 6:25 PM

On 2/14/2024 9:47 AM, Steve Lelievre via Discuss wrote:

Hi everyone,

I am using OpenSCAD to generate a 2-dimensional vector that I wish to

treat as a heightmap. If I had the data in a file, I could load it

using 'surface' and to produce exactly what I want, because surface

fills in the areas between the height points to produce a continuous

form.

How do I do the same thing directly from my vector?

I feel that there must be a way but today I am not seeing it, short of

processing the vector to construct a polyhedron ... surely there must

be an easier way?

Right now, it's "process the vector to produce a polyhedron". I tried a

bit to extend surface() to process arrays, but ran into some

data-representation problems and haven't gotten back to it.

Here's a module I wrote a while back. Call it like

"sfc([[0,2,1],[2,1,0],[1,2,2]], [10,10,1]);"

The randomness toward the end is to break up visual patterns that form

if each cell is always triangulated in the same direction. The size

parameter controls the X and Y size, and the Z size of the "base".

module sfc(a, sz) {

function dataIndex(x, y) = dataBase + x*ny + y;

nx = len(a);

ny = len(a[0]);

corners = 0;

dataBase = corners + 4;

```
pts = [
[0, 0, -sz.z],
[nx-1, 0, -sz.z],
[nx-1, ny-1, -sz.z],
[0, ny-1, -sz.z],
for (x = [0:nx-1])
for (y = [0:ny-1])
[ x, y, a[x][y] ]
];
faces = [
[ corners+0, corners+1, corners+2 ],
[ corners+0, corners+2, corners+3 ],
[
each for (x=[0:nx-1]) dataIndex(x,0),
corners+1,
corners+0,
],
[
each for (y=[0:ny-1]) dataIndex(nx-1,y),
corners+2,
corners+1,
],
[
each for (x=[nx-1:-1:0]) dataIndex(x,ny-1),
corners+3,
corners+2,
],
[
each for (y=[ny-1:-1:0]) dataIndex(0,y),
corners+0,
corners+3,
],
each for (x=[0:nx-2], y=[0:ny-2])
if (rands(0,1,1)[0]>0.5) [
[ dataIndex(x+1, y), dataIndex(x, y), dataIndex(x, y+1) ],
[ dataIndex(x+1, y+1), dataIndex(x+1, y), dataIndex(x, y+1) ],
] else [
[ dataIndex(x+1, y), dataIndex(x, y), dataIndex(x+1, y+1) ],
[ dataIndex(x+1, y+1), dataIndex(x, y), dataIndex(x, y+1) ],
],
];
scale([sz.x/(nx-1),sz.y/(ny-1),1])
polyhedron(pts, faces);
```

}

On 2/14/2024 9:47 AM, Steve Lelievre via Discuss wrote:
> Hi everyone,
>
> I am using OpenSCAD to generate a 2-dimensional vector that I wish to
> treat as a heightmap. If I had the data in a file, I could load it
> using 'surface' and to produce exactly what I want, because surface
> fills in the areas between the height points to produce a continuous
> form.
>
> How do I do the same thing directly from my vector?
>
> I feel that there must be a way but today I am not seeing it, short of
> processing the vector to construct a polyhedron ... surely there must
> be an easier way?
Right now, it's "process the vector to produce a polyhedron". I tried a
bit to extend surface() to process arrays, but ran into some
data-representation problems and haven't gotten back to it.
Here's a module I wrote a while back. Call it like
"sfc([[0,2,1],[2,1,0],[1,2,2]], [10,10,1]);"
The randomness toward the end is to break up visual patterns that form
if each cell is always triangulated in the same direction. The size
parameter controls the X and Y size, and the Z size of the "base".
module sfc(a, sz) {
function dataIndex(x, y) = dataBase + x*ny + y;
nx = len(a);
ny = len(a[0]);
corners = 0;
dataBase = corners + 4;
pts = [
[0, 0, -sz.z],
[nx-1, 0, -sz.z],
[nx-1, ny-1, -sz.z],
[0, ny-1, -sz.z],
for (x = [0:nx-1])
for (y = [0:ny-1])
[ x, y, a[x][y] ]
];
faces = [
[ corners+0, corners+1, corners+2 ],
[ corners+0, corners+2, corners+3 ],
[
each for (x=[0:nx-1]) dataIndex(x,0),
corners+1,
corners+0,
],
[
each for (y=[0:ny-1]) dataIndex(nx-1,y),
corners+2,
corners+1,
],
[
each for (x=[nx-1:-1:0]) dataIndex(x,ny-1),
corners+3,
corners+2,
],
[
each for (y=[ny-1:-1:0]) dataIndex(0,y),
corners+0,
corners+3,
],
each for (x=[0:nx-2], y=[0:ny-2])
if (rands(0,1,1)[0]>0.5) [
[ dataIndex(x+1, y), dataIndex(x, y), dataIndex(x, y+1) ],
[ dataIndex(x+1, y+1), dataIndex(x+1, y), dataIndex(x, y+1) ],
] else [
[ dataIndex(x+1, y), dataIndex(x, y), dataIndex(x+1, y+1) ],
[ dataIndex(x+1, y+1), dataIndex(x, y), dataIndex(x, y+1) ],
],
];
scale([sz.x/(nx-1),sz.y/(ny-1),1])
polyhedron(pts, faces);
}

SL

Steve Lelievre

Wed, Feb 14, 2024 7:12 PM

Thanks, that is useful.

Steve

On 2024-02-14 10:25 a.m., Jordan Brown wrote:

Right now, it's "process the vector to produce a polyhedron". I tried

a bit to extend surface() to process arrays, but ran into some

data-representation problems and haven't gotten back to it.

Here's a module I wrote a while back.

Thanks, that is useful.
Steve
On 2024-02-14 10:25 a.m., Jordan Brown wrote:
> Right now, it's "process the vector to produce a polyhedron". I tried
> a bit to extend surface() to process arrays, but ran into some
> data-representation problems and haven't gotten back to it.
>
> Here's a module I wrote a while back.

RD

Revar Desmera

Wed, Feb 14, 2024 11:03 PM

In BOSL2 I’d use the `heightfield()`

module.

-Revar

On Feb 14, 2024, at 11:13 AM, Steve Lelievre via Discuss <discuss@lists.openscad.org> wrote:

Thanks, that is useful.

Steve

On 2024-02-14 10:25 a.m., Jordan Brown wrote:

Right now, it's "process the vector to produce a polyhedron". I tried a bit to extend surface() to process arrays, but ran into some data-representation problems and haven't gotten back to it.

Here's a module I wrote a while back.

_______________________________________________

OpenSCAD mailing list

To unsubscribe send an email to discuss-leave@lists.openscad.org

Replying to:

Empathy v1.0
2024 ©Harmonylists.com