# intersecting with an hyperbola

35 messages
12
Open this post in threaded view
|

## intersecting with an hyperbola

 I need advice on how to model an hyperbola (i.e., z=xy). There's no primitive like sphere() or cylinder() so I'm wondering what would be the best way to do it. In case it matters, my goal is to intersect it with a sphere to cut the sphere in half.
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 This depends somewhat on what kind of resolution you need.You can stitch together a polyhedron from scratch.Or you use the easy to understand, but slow chain-hull method.Here is an example for a one dimensional case: z=x*x.Generalize it to two dimensions and your good to go.Just limit the \$fn of the spheres to small numbers.​for (i=[-10:10-1]){    hull(){        s(i);        s(i+1);        t(i);        t(i+1);    }}    module s(i){    translate([i,0,0.1*i*i])sphere(r=1,\$fn=8);    }module t(i){    translate([i,0,0])sphere(r=1,\$fn=8);}2015-12-23 16:44 GMT+01:00 Mekko :I need advice on how to model an hyperbola (i.e., z=xy). There's no primitive like sphere() or cylinder() so I'm wondering what would be the best way to do it. In case it matters, my goal is to intersect it with a sphere to cut the sphere in half. -- View this message in context: http://forum.openscad.org/intersecting-with-an-hyperbola-tp15280.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: intersecting with an hyperbola

Open this post in threaded view
|

## Re: intersecting with an hyperbola

 On 12/23/2015 05:20 PM, Peter Falke wrote: > Or have a look at thingiverse. > I googled: thingiverse openscad function f(x) > and found this: > > http://www.thingiverse.com/thing:24897> > by dnewman > > This seems to be written before the list comprehension features were available so it uses a union of lots of small polyhedrons which will make it quite slow at higher resolutions. The 3d-function.scad might be able to generate a similar 3d-plot too as single polyhedron: https://github.com/openscad/list-comprehension-demosciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 In reply to this post by Mekko try something like this: \$fn=100; difference() {   sphere(.99);   rotate_extrude()   polygon(points = concat([[0,1]], hyperbola(1, .02))); } function hyperbola(X, step) = [for(i=[0:step:X])[i, i*i]];   - Rudolf
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 On 12/23/2015 06:03 PM, Parkinbot wrote: > try something like this: > Ahh, very good point. Using rotate_extrude is much better. ciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 It isn't the right shape though, unless I misunderstand the original question. A rotated hyperbola is not the same as a 3D hyperbola z = x * y.On 23 December 2015 at 17:11, Torsten Paul wrote:On 12/23/2015 06:03 PM, Parkinbot wrote: > try something like this: > Ahh, very good point. Using rotate_extrude is much better. ciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 It looks like this: -Here is the code I used to make it:xmin = 0;xmax = 1;ymin = 0;ymax = 1;step = 0.05;xpoints = floor((xmax - xmin) / step) + 1;ypoints = floor((ymax - ymin) / step) + 1;function index(x,y) = x * ypoints + y + 1;function x(i) = xmin + i * step;function y(i) = ymin + i * step;points = concat([[x(xpoints - 1), y(ypoints - 1), 0]],         [for(i = [0 : xpoints - 1]) for(j = [0 : ypoints - 1]) [x(i), y(j), x(i) * y(j)]]);function flatten(l) = [for(a = l) for (b = a) b];base = [[0, 1, index(xpoints -1, 0)],        [1, 0, index(0, ypoints -1)],        [0, index(xpoints - 1, ypoints - 1), index(0, ypoints - 1)],        [0, index(xpoints - 1, 0), index(xpoints - 1, ypoints - 1)],       ];    faces = flatten([for(i = [0 : xpoints - 2]) for(j = [0 : ypoints - 2])          [[index(i,j), index(i, j + 1), index(i + 1, j + 1)],          [index(i + 1, j + 1), index(i + 1, j ), index(i, j)]]        ]);    polyhedron(points, concat(base, faces));​On 23 December 2015 at 17:15, nop head wrote:It isn't the right shape though, unless I misunderstand the original question. A rotated hyperbola is not the same as a 3D hyperbola z = x * y.On 23 December 2015 at 17:11, Torsten Paul wrote:On 12/23/2015 06:03 PM, Parkinbot wrote: > try something like this: > Ahh, very good point. Using rotate_extrude is much better. ciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: intersecting with an hyperbola

Open this post in threaded view
|

## Re: intersecting with an hyperbola

 In reply to this post by nophead Exactly right, nophead: a rotated 2D hyperbola != a 3D hyperbola. Thanks for the code! I need the actual saddle area and when I put in -1 for the minimum x and y values (instead of 0), it kind of "self-intersects" through the origin as it ties the faces to [1,1,0] and [-1,-1,1]. I suppose I could whack "points = concat([[x(xpoints - 1), y(ypoints - 1), 0]], ..." and change the 0 to like -5 or something but it worries me that I don't understand the code well enough to cover this case properly.  Can you show me the correct way?
Open this post in threaded view
|

## Re: intersecting with an hyperbola

Open this post in threaded view
|

## Re: intersecting with an hyperbola

Open this post in threaded view
|

## Re: intersecting with an hyperbola

 In reply to this post by nophead That's exactly what I needed. Thank you! Cutting a sphere with it throws an exception for some reason. This code: difference() {     sphere(r=.5, \$fn=20);     polyhedron(points, concat(base, faces)); } generates this error: ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /data/OpenSCAD/libraries-mingw32-master/mxe/usr/i686-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326 Suggestions?
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 It is because I closed the faces with single triangles creating lots of t junctions where the small triangles meet. It needs to be closed with triangle fans, my mistake.On 23 December 2015 at 19:24, Mekko wrote:That's exactly what I needed. Thank you! Cutting a sphere with it throws an exception for some reason. This code: difference() {     sphere(r=.5, \$fn=20);     polyhedron(points, concat(base, faces)); } generates this error: ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /data/OpenSCAD/libraries-mingw32-master/mxe/usr/i686-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326 Suggestions? -- View this message in context: http://forum.openscad.org/intersecting-with-an-hyperbola-tp15280p15291.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 Here is one that works: -xmin = -1;xmax = 1;ymin = -1;ymax = 1;step = 0.1;zmin = min(xmin *ymax, xmax * ymin);xpoints = floor((xmax - xmin) / step) + 1;ypoints = floor((ymax - ymin) / step) + 1;function index(x,y) = x * ypoints + y + 2;function x(i) = xmin + i * step;function y(i) = ymin + i * step;points = concat([[xmin, ymin, zmin]],                [[xmax, ymax, zmin]],         [for(i = [0 : xpoints - 1]) for(j = [0 : ypoints - 1]) [x(i), y(j), x(i) * y(j)]]);function flatten(l) = [for(a = l) for (b = a) b];base = [        [1, 0, index(xpoints -1, 0)],        [0, 1, index(0, ypoints -1)],        flatten([for(i = [0 : xpoints - 2]) [0, index(i, 0), index(i + 1,0)]]),        flatten([for(j = [0 : ypoints - 2]) [0, index(0, j), index(0, j + 1)]]),        flatten([for(i = [0 : xpoints - 2]) [1, index(i + 1, ypoints - 1), index(i, ypoints - 1)]]),        flatten([for(j = [0 : ypoints - 2]) [1, index(xpoints - 1, j), index(xpoints - 1, j + 1)]]),       ];   faces = flatten([for(i = [0 : xpoints - 2]) for(j = [0 : ypoints - 2])         [[index(i,j), index(i, j + 1), index(i + 1, j + 1)],          [index(i + 1, j + 1), index(i + 1, j ), index(i, j)]]        ]);difference() {    sphere(r=.5, \$fn=20);    polyhedron(points, concat(base, faces), convexity = 2);} On 23 December 2015 at 19:37, nop head wrote:It is because I closed the faces with single triangles creating lots of t junctions where the small triangles meet. It needs to be closed with triangle fans, my mistake.On 23 December 2015 at 19:24, Mekko wrote:That's exactly what I needed. Thank you! Cutting a sphere with it throws an exception for some reason. This code: difference() {     sphere(r=.5, \$fn=20);     polyhedron(points, concat(base, faces)); } generates this error: ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /data/OpenSCAD/libraries-mingw32-master/mxe/usr/i686-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326 Suggestions? -- View this message in context: http://forum.openscad.org/intersecting-with-an-hyperbola-tp15280p15291.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: intersecting with an hyperbola

Open this post in threaded view
|

## Re: intersecting with an hyperbola

Open this post in threaded view
|

## Re: intersecting with an hyperbola

 This stuff is way over my head but FWIW, this code: intersection() {     polyhedron(points, concat(base, faces), convexity = 2);     sphere(r=.5, \$fn=80); } generates a preview of a zero-thickness contour (that looks like a potato chip). That is, the intersection() shows only where the *surface* of the polyhedron intersects with the volume of the sphere and excludes all the volume that the two objects share. Maybe that is useful to know.
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 For some reason GCAL doesn't like my polyhedron but I can't see why. I can export it to an STL and it looks fine in netfabb as well.On 23 December 2015 at 23:01, Mekko wrote:This stuff is way over my head but FWIW, this code: intersection() {     polyhedron(points, concat(base, faces), convexity = 2);     sphere(r=.5, \$fn=80); } generates a preview of a zero-thickness contour (that looks like a potato chip). That is, the intersection() shows only where the *surface* of the polyhedron intersects with the volume of the sphere and excludes all the volume that the two objects share. Maybe that is useful to know. -- View this message in context: http://forum.openscad.org/intersecting-with-an-hyperbola-tp15280p15300.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: intersecting with an hyperbola

 1. If I change for(i = [0 : xpoints - 1])    to for(i = [0 : xpoints - 0])    I see no visual change. 2. Also when I F6 the object I get a result but its not using the color scheme I've chosen.     I think this means there is something wrong with the model. 3. If I reverse the difference: difference() {         polyhedron(points, concat(base, faces), convexity = 2);         sphere(r=.5, \$fn=45); }   I get a CGAL error - coincident face. ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /data/OpenSCAD/libraries-mingw64-master/mxe-w64/usr/x86_64-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326 Looks like one of the indices is off in base=... ??maybe?? still looking
12