R
Rudolf
Fri, Feb 14, 2025 10:51 PM
Sorry guys to open the theme again, but I can't reply to it, as I wasn't
on the list when it was posted and found the thread on the Empathy web
mirror ...
So, here is my compact code for the super ellipsoid. I used a tricky
hull to display the output. However this obviously only works for convex
shapes i.e. nx, ny, nz values >= 1
points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
// draw point cloud (hull() works for convex shapes only)
hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
[ for(u=[-90:step:90], v=[0:step:360])
let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(cos(v))pow(abs(cos(v)),2/ny))
let(y = bsign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(sin(v))pow(abs(sin(v)),2/ny))
let(z = csign(sin(u)) *pow(abs(sin(u)),2/nz))
[x,y,z]
];
Sorry guys to open the theme again, but I can't reply to it, as I wasn't
on the list when it was posted and found the thread on the Empathy web
mirror ...
So, here is my compact code for the super ellipsoid. I used a tricky
hull to display the output. However this obviously only works for convex
shapes i.e. nx, ny, nz values >= 1
points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
// draw point cloud (hull() works for convex shapes only)
hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
[ for(u=[-90:step:90], v=[0:step:360])
let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(cos(v))*pow(abs(cos(v)),2/ny))
let(y = b*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(sin(v))*pow(abs(sin(v)),2/ny))
let(z = c*sign(sin(u)) *pow(abs(sin(u)),2/nz))
[x,y,z]
];
AM
Adrian Mariano
Sat, Feb 15, 2025 12:24 AM
I think it's been quite a long time since that hack was discussed here.
One discovery from the last time around is that it's faster (I think
possibly a lot faster) to divide your points into triangles rather than
passing one huge "face". Maybe it triangulates the face? This hack is in
BOSL2 as hull_points().
On Fri, Feb 14, 2025 at 5:52 PM Rudolf via Discuss <
discuss@lists.openscad.org> wrote:
Sorry guys to open the theme again, but I can't reply to it, as I wasn't
on the list when it was posted and found the thread on the Empathy web
mirror ...
So, here is my compact code for the super ellipsoid. I used a tricky hull
to display the output. However this obviously only works for convex shapes
i.e. nx, ny, nz values >= 1
points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
// draw point cloud (hull() works for convex shapes only)
hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
[ for(u=[-90:step:90], v=[0:step:360])
let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(cos(v))pow(abs(cos(v)),2/ny))
let(y = bsign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(sin(v))pow(abs(sin(v)),2/ny))
let(z = csign(sin(u)) *pow(abs(sin(u)),2/nz))
[x,y,z]
];
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I think it's been quite a long time since that hack was discussed here.
One discovery from the last time around is that it's faster (I think
possibly a lot faster) to divide your points into triangles rather than
passing one huge "face". Maybe it triangulates the face? This hack is in
BOSL2 as hull_points().
On Fri, Feb 14, 2025 at 5:52 PM Rudolf via Discuss <
discuss@lists.openscad.org> wrote:
> Sorry guys to open the theme again, but I can't reply to it, as I wasn't
> on the list when it was posted and found the thread on the Empathy web
> mirror ...
>
> So, here is my compact code for the super ellipsoid. I used a tricky hull
> to display the output. However this obviously only works for convex shapes
> i.e. nx, ny, nz values >= 1
>
> points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
>
> // draw point cloud (hull() works for convex shapes only)
> hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
>
> function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
> [ for(u=[-90:step:90], v=[0:step:360])
> let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
> sign(cos(v))*pow(abs(cos(v)),2/ny))
> let(y = b*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
> sign(sin(v))*pow(abs(sin(v)),2/ny))
> let(z = c*sign(sin(u)) *pow(abs(sin(u)),2/nz))
> [x,y,z]
> ];
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
SP
Sanjeev Prabhakar
Sat, Feb 15, 2025 1:51 AM
The original mail was not a super ellipsoid.
It was made by the use of bspline curves if I remember correctly.
On Sat, 15 Feb, 2025, 4:21 am Rudolf via Discuss, <
discuss@lists.openscad.org> wrote:
Sorry guys to open the theme again, but I can't reply to it, as I wasn't
on the list when it was posted and found the thread on the Empathy web
mirror ...
So, here is my compact code for the super ellipsoid. I used a tricky hull
to display the output. However this obviously only works for convex shapes
i.e. nx, ny, nz values >= 1
points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
// draw point cloud (hull() works for convex shapes only)
hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
[ for(u=[-90:step:90], v=[0:step:360])
let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(cos(v))pow(abs(cos(v)),2/ny))
let(y = bsign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(sin(v))pow(abs(sin(v)),2/ny))
let(z = csign(sin(u)) *pow(abs(sin(u)),2/nz))
[x,y,z]
];
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
The original mail was not a super ellipsoid.
It was made by the use of bspline curves if I remember correctly.
On Sat, 15 Feb, 2025, 4:21 am Rudolf via Discuss, <
discuss@lists.openscad.org> wrote:
> Sorry guys to open the theme again, but I can't reply to it, as I wasn't
> on the list when it was posted and found the thread on the Empathy web
> mirror ...
>
> So, here is my compact code for the super ellipsoid. I used a tricky hull
> to display the output. However this obviously only works for convex shapes
> i.e. nx, ny, nz values >= 1
>
> points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
>
> // draw point cloud (hull() works for convex shapes only)
> hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
>
> function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
> [ for(u=[-90:step:90], v=[0:step:360])
> let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
> sign(cos(v))*pow(abs(cos(v)),2/ny))
> let(y = b*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
> sign(sin(v))*pow(abs(sin(v)),2/ny))
> let(z = c*sign(sin(u)) *pow(abs(sin(u)),2/nz))
> [x,y,z]
> ];
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
SP
Sanjeev Prabhakar
Sat, Feb 15, 2025 1:55 AM
sorry, please ignore, I pasted some other message it seems.
On Sat, 15 Feb 2025 at 07:21, Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:
The original mail was not a super ellipsoid.
It was made by the use of bspline curves if I remember correctly.
On Sat, 15 Feb, 2025, 4:21 am Rudolf via Discuss, <
discuss@lists.openscad.org> wrote:
Sorry guys to open the theme again, but I can't reply to it, as I wasn't
on the list when it was posted and found the thread on the Empathy web
mirror ...
So, here is my compact code for the super ellipsoid. I used a tricky hull
to display the output. However this obviously only works for convex shapes
i.e. nx, ny, nz values >= 1
points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
// draw point cloud (hull() works for convex shapes only)
hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
[ for(u=[-90:step:90], v=[0:step:360])
let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(cos(v))pow(abs(cos(v)),2/ny))
let(y = bsign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(sin(v))pow(abs(sin(v)),2/ny))
let(z = csign(sin(u)) *pow(abs(sin(u)),2/nz))
[x,y,z]
];
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
sorry, please ignore, I pasted some other message it seems.
On Sat, 15 Feb 2025 at 07:21, Sanjeev Prabhakar <sprabhakar2006@gmail.com>
wrote:
> The original mail was not a super ellipsoid.
> It was made by the use of bspline curves if I remember correctly.
>
>
> On Sat, 15 Feb, 2025, 4:21 am Rudolf via Discuss, <
> discuss@lists.openscad.org> wrote:
>
>> Sorry guys to open the theme again, but I can't reply to it, as I wasn't
>> on the list when it was posted and found the thread on the Empathy web
>> mirror ...
>>
>> So, here is my compact code for the super ellipsoid. I used a tricky hull
>> to display the output. However this obviously only works for convex shapes
>> i.e. nx, ny, nz values >= 1
>>
>> points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
>>
>> // draw point cloud (hull() works for convex shapes only)
>> hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
>>
>> function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
>> [ for(u=[-90:step:90], v=[0:step:360])
>> let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
>> sign(cos(v))*pow(abs(cos(v)),2/ny))
>> let(y = b*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
>> sign(sin(v))*pow(abs(sin(v)),2/ny))
>> let(z = c*sign(sin(u)) *pow(abs(sin(u)),2/nz))
>> [x,y,z]
>> ];
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
>
SP
Sanjeev Prabhakar
Sat, Feb 15, 2025 1:59 AM
original shape posted was this:
[image: Screenshot 2025-01-27 at 9.35.07 PM.png]
On Sat, 15 Feb 2025 at 07:25, Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:
sorry, please ignore, I pasted some other message it seems.
On Sat, 15 Feb 2025 at 07:21, Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:
The original mail was not a super ellipsoid.
It was made by the use of bspline curves if I remember correctly.
On Sat, 15 Feb, 2025, 4:21 am Rudolf via Discuss, <
discuss@lists.openscad.org> wrote:
Sorry guys to open the theme again, but I can't reply to it, as I wasn't
on the list when it was posted and found the thread on the Empathy web
mirror ...
So, here is my compact code for the super ellipsoid. I used a tricky
hull to display the output. However this obviously only works for convex
shapes i.e. nx, ny, nz values >= 1
points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
// draw point cloud (hull() works for convex shapes only)
hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
[ for(u=[-90:step:90], v=[0:step:360])
let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(cos(v))pow(abs(cos(v)),2/ny))
let(y = bsign(cos(u)) *pow(abs(cos(u)),2/nx) *
sign(sin(v))pow(abs(sin(v)),2/ny))
let(z = csign(sin(u)) *pow(abs(sin(u)),2/nz))
[x,y,z]
];
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
original shape posted was this:
[image: Screenshot 2025-01-27 at 9.35.07 PM.png]
On Sat, 15 Feb 2025 at 07:25, Sanjeev Prabhakar <sprabhakar2006@gmail.com>
wrote:
> sorry, please ignore, I pasted some other message it seems.
>
>
> On Sat, 15 Feb 2025 at 07:21, Sanjeev Prabhakar <sprabhakar2006@gmail.com>
> wrote:
>
>> The original mail was not a super ellipsoid.
>> It was made by the use of bspline curves if I remember correctly.
>>
>>
>> On Sat, 15 Feb, 2025, 4:21 am Rudolf via Discuss, <
>> discuss@lists.openscad.org> wrote:
>>
>>> Sorry guys to open the theme again, but I can't reply to it, as I wasn't
>>> on the list when it was posted and found the thread on the Empathy web
>>> mirror ...
>>>
>>> So, here is my compact code for the super ellipsoid. I used a tricky
>>> hull to display the output. However this obviously only works for convex
>>> shapes i.e. nx, ny, nz values >= 1
>>>
>>> points = Superellipse(a=10, b=20, c=30, nx=2, ny=2, nz=2, step=3);
>>>
>>> // draw point cloud (hull() works for convex shapes only)
>>> hull() polyhedron(points, [[for(i=[0:len(points)-1]) i]]);
>>>
>>> function Superellipse(a=1, b=1, c=1, nx=2, ny=2, nz=2, step=10) =
>>> [ for(u=[-90:step:90], v=[0:step:360])
>>> let(x = a*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
>>> sign(cos(v))*pow(abs(cos(v)),2/ny))
>>> let(y = b*sign(cos(u)) *pow(abs(cos(u)),2/nx) *
>>> sign(sin(v))*pow(abs(sin(v)),2/ny))
>>> let(z = c*sign(sin(u)) *pow(abs(sin(u)),2/nz))
>>> [x,y,z]
>>> ];
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>>
>>
F
FPA
Sat, Feb 15, 2025 4:28 PM
Hello,
I'm wondering, is there a way to test in Openscad an array for the
existence of a value?
e.g.
modus=[0,2,4,6]; // this is the array
var=3; // this my set value
if (var @ modus) then ... (@ stands for the unknown operator in my example)
I scanned through the wiki but couldn't find the answer.
Thanks in advance.
fred
Hello,
I'm wondering, is there a way to test in Openscad an array for the
existence of a value?
e.g.
modus=[0,2,4,6]; // this is the array
var=3; // this my set value
if (var @ modus) then ... (@ stands for the unknown operator in my example)
I scanned through the wiki but couldn't find the answer.
Thanks in advance.
fred
DP
Dan Perry
Sat, Feb 15, 2025 4:37 PM
Hello,
I'm wondering, is there a way to test in Openscad an array for the
existence of a value?
e.g.
modus=[0,2,4,6]; // this is the array
var=3; // this my set value
if (var @ modus) then ... (@ stands for the unknown operator in my
example)
I scanned through the wiki but couldn't find the answer.
Thanks in advance.
fred
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
There are similar examples in the documentation.
Dan
On Sat, Feb 15, 2025 at 4:29 PM FPA via Discuss <discuss@lists.openscad.org>
wrote:
> Hello,
>
> I'm wondering, is there a way to test in Openscad an array for the
> existence of a value?
>
> e.g.
> modus=[0,2,4,6]; // this is the array
> var=3; // this my set value
> if (var @ modus) then ... (@ stands for the unknown operator in my
> example)
> I scanned through the wiki but couldn't find the answer.
>
> Thanks in advance.
>
> fred
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
AM
Adrian Mariano
Sat, Feb 15, 2025 4:45 PM
I think what he's looking for is the search function. So something like
search([var], modus). Note, the syntax and behavior of search is bizarre.
On Sat, Feb 15, 2025 at 11:37 AM Dan Perry via Discuss <
discuss@lists.openscad.org> wrote:
Hello,
I'm wondering, is there a way to test in Openscad an array for the
existence of a value?
e.g.
modus=[0,2,4,6]; // this is the array
var=3; // this my set value
if (var @ modus) then ... (@ stands for the unknown operator in my
example)
I scanned through the wiki but couldn't find the answer.
Thanks in advance.
fred
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I think what he's looking for is the search function. So something like
search([var], modus). Note, the syntax and behavior of search is bizarre.
On Sat, Feb 15, 2025 at 11:37 AM Dan Perry via Discuss <
discuss@lists.openscad.org> wrote:
> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
>
> There are similar examples in the documentation.
> Dan
>
>
> On Sat, Feb 15, 2025 at 4:29 PM FPA via Discuss <
> discuss@lists.openscad.org> wrote:
>
>> Hello,
>>
>> I'm wondering, is there a way to test in Openscad an array for the
>> existence of a value?
>>
>> e.g.
>> modus=[0,2,4,6]; // this is the array
>> var=3; // this my set value
>> if (var @ modus) then ... (@ stands for the unknown operator in my
>> example)
>> I scanned through the wiki but couldn't find the answer.
>>
>> Thanks in advance.
>>
>> fred
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
RD
Revar Desmera
Sat, Feb 15, 2025 7:35 PM
On Feb 15, 2025, at 8:29 AM, FPA via Discuss discuss@lists.openscad.org wrote:
I'm wondering, is there a way to test in Openscad an array for the
existence of a value?
BOSL2 has a fairly optimized in_list() implementation that gets around the oddities of search(), while taking advantage of its speed. Here’s a de-BOSL2’ed version of the code it uses:
// Function: in_list()
// Synopsis: Returns true if a value is in a list.
// Topics: List Handling
// See Also: select(), slice()
// Usage:
// bool = in_list(val, list, [idx]);
// Description:
// Returns true if value val is in list list. When val==NAN the answer will be false for any list.
// Arguments:
// val = The simple value to search for.
// list = The list to search.
// idx = If given, searches the given columns for matches for val.
// Example:
// a = in_list("bar", ["foo", "bar", "baz"]); // Returns true.
// b = in_list("bee", ["foo", "bar", "baz"]); // Returns false.
// c = in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1); // Returns true.
// Note that a huge complication occurs because OpenSCAD's search() finds
// index i as a hits if the val equals list[i] but also if val equals list[i][0].
// This means every hit needs to be checked to see if it's actually a hit,
// and if the first hit is a mismatch we have to keep searching.
// We assume that the normal case doesn't have mixed data, and try first
// with just one hit, but if this finds a mismatch then we try again
// with all hits, which could be slow for long lists.
function in_list(val,list,idx) =
assert(is_list(list),"Input is not a list")
assert(is_undef(idx) || is_num(idx), "Invalid idx value.")
let( firsthit = search([val], list, num_returns_per_match=1, index_col_num=idx)[0] )
firsthit==[] ? false
: is_undef(idx) && val==list[firsthit] ? true
: !is_undef(idx) && val==list[firsthit][idx] ? true
// first hit was found but didn't match, so try again with all hits
: let ( allhits = search([val], list, 0, idx)[0])
is_undef(idx) ? [for(hit=allhits) if (list[hit]==val) 1] != []
: [for(hit=allhits) if (list[hit][idx]==val) 1] != [];
> On Feb 15, 2025, at 8:29 AM, FPA via Discuss <discuss@lists.openscad.org> wrote:
> I'm wondering, is there a way to test in Openscad an array for the
> existence of a value?
BOSL2 has a fairly optimized `in_list()` implementation that gets around the oddities of `search()`, while taking advantage of its speed. Here’s a de-BOSL2’ed version of the code it uses:
// Function: in_list()
// Synopsis: Returns true if a value is in a list.
// Topics: List Handling
// See Also: select(), slice()
// Usage:
// bool = in_list(val, list, [idx]);
// Description:
// Returns true if value `val` is in list `list`. When `val==NAN` the answer will be false for any list.
// Arguments:
// val = The simple value to search for.
// list = The list to search.
// idx = If given, searches the given columns for matches for `val`.
// Example:
// a = in_list("bar", ["foo", "bar", "baz"]); // Returns true.
// b = in_list("bee", ["foo", "bar", "baz"]); // Returns false.
// c = in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1); // Returns true.
// Note that a huge complication occurs because OpenSCAD's search() finds
// index i as a hits if the val equals list[i] but also if val equals list[i][0].
// This means every hit needs to be checked to see if it's actually a hit,
// and if the first hit is a mismatch we have to keep searching.
// We assume that the normal case doesn't have mixed data, and try first
// with just one hit, but if this finds a mismatch then we try again
// with all hits, which could be slow for long lists.
function in_list(val,list,idx) =
assert(is_list(list),"Input is not a list")
assert(is_undef(idx) || is_num(idx), "Invalid idx value.")
let( firsthit = search([val], list, num_returns_per_match=1, index_col_num=idx)[0] )
firsthit==[] ? false
: is_undef(idx) && val==list[firsthit] ? true
: !is_undef(idx) && val==list[firsthit][idx] ? true
// first hit was found but didn't match, so try again with all hits
: let ( allhits = search([val], list, 0, idx)[0])
is_undef(idx) ? [for(hit=allhits) if (list[hit]==val) 1] != []
: [for(hit=allhits) if (list[hit][idx]==val) 1] != [];
- Revar
F
fpa512 (at) email.com
Mon, Feb 17, 2025 10:40 PM
I think what he's looking for is the search function. So something like
search([var], modus). Note, the syntax and behavior of search is bizarre.
On Sat, Feb 15, 2025 at 11:37 AM Dan Perry via Discuss <
discuss@lists.openscad.org> wrote:
Hello,
I'm wondering, is there a way to test in Openscad an array for the
existence of a value?
e.g.
modus=[0,2,4,6]; // this is the array
var=3; // this my set value
if (var @ modus) then ... (@ stands for the unknown operator in my
example)
I scanned through the wiki but couldn't find the answer.
Thanks in advance.
fred
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I came up with the following solution
list1=[0,1,2];
modus=2;
result=len(search(modus, list1));
echo(result);
if (result>0) {
echo("result is ", result);
}
else {
echo("there is nothing");
};
// or ...
if (len(search(modus, list1))) {
echo ("modus " , modus, "is detected");
};
Btw. This thread never showed up my email client. Any explanation why that could be?
Adrian Mariano wrote:
> I think what he's looking for is the search function. So something like
> search(\[var\], modus). Note, the syntax and behavior of search is bizarre.
>
> On Sat, Feb 15, 2025 at 11:37 AM Dan Perry via Discuss <
> discuss@lists.openscad.org> wrote:
>
> > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions
> >
> > There are similar examples in the documentation.
> > Dan
> >
> > On Sat, Feb 15, 2025 at 4:29 PM FPA via Discuss <
> > discuss@lists.openscad.org> wrote:
> >
> > > Hello,
> > >
> > > I'm wondering, is there a way to test in Openscad an array for the
> > > existence of a value?
> > >
> > > e.g.
> > > modus=\[0,2,4,6\]; // this is the array
> > > var=3; // this my set value
> > > if (var @ modus) then ... (@ stands for the unknown operator in my
> > > example)
> > > I scanned through the wiki but couldn't find the answer.
> > >
> > > Thanks in advance.
> > >
> > > fred
> > >
> > > ---
> > >
> > > OpenSCAD mailing list
> > > To unsubscribe send an email to discuss-leave@lists.openscad.org
> >
> > ---
> >
> > OpenSCAD mailing list
> > To unsubscribe send an email to discuss-leave@lists.openscad.org
I came up with the following solution
> list1=\[0,1,2\];
>
> modus=2;
>
> result=len(search(modus, list1));
>
> echo(result);
>
> if (result>0) {
>
> echo("result is ", result);
>
> }
>
> else {
>
> echo("there is nothing");
>
> };
>
> // or ...
>
> if (len(search(modus, list1))) {
>
> echo ("modus " , modus, "is detected");
>
> };
Btw. This thread never showed up my email client. Any explanation why that could be?