# How to make a cylinder perpendicular to a sloping face

26 messages
12
Open this post in threaded view
|

## How to make a cylinder perpendicular to a sloping face

 I have not been able to find an answer to this with Google or after a lot of YouTube browsing - it may just be that I don't know the correct search terms. If I create a cube I know that each of the vertical faces is at 90deg so it is easy to rotate a cylinder so it sits perpendicular to a face. But if I create a prism by extruding a polygon with one face of the prism at a slope how do I rotate a cylinder so it sits perpendicular to the sloping face? With Freecad and SolveSpace it is possible to start a sketch on any surface of an object but that concept does not exist with Openscad. However I find the way that Openscad works much easier to deal with. Thanks ...R -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 In reply to this post by Robin2 Not sure if this will help but I worked out this routine to draw a cylinder between two arbitrary points. /************************************  * *  * Draw a rod between two arbitrary points *  * p1 and p2 are the end points [x,y,z] *  * The diameter of the rod is 'dia/2' and        *  * each end point is 'marked' with a sphere *  * of diameter 'dia'. *  * *  ***********************************/ module rod(p1, p2, dia) {         Xdist = p2[0] - p1[0];         Ydist = p2[1] - p1[1];         Zdist = p2[2] - p1[2];         length = norm([Xdist,Ydist,Zdist]); // radial distance         b = acos(Zdist/length); // inclination angle         c = atan2(Ydist,Xdist);     // azimuthal angle         translate(p1)         {                 rotate([0, b, c])                 {                         cylinder(h=length, d=dia);                 }         } } PhilipJ -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 In reply to this post by Robin2 I would probably use one of the formulae for finding the slope of a line. There's a handy calulator for it... https://www.omnicalculator.com/math/slope that also shows the formulae. A quick Google, using the term "find the slope of a line" brought up a lot of hits. -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 Thanks for the answers.  I had been assuming that there is a simpler way within Openscad that I had missed. Must brush off my sin cos and tan. Just out of curiosity is the need to align things with sloping sides something that is rarely if ever needed in practice? ...R -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 On 2019-09-06 01:28, adrianv wrote: > Yes, some task might be done by a function that uses trigonometry, but > the > higher level abstraction of hiding the trig in a function will produce > code > that is easier to write and easier to read next week.  At least, that's > my > opinion.  And it doesn't just apply to trigonometry, but any > geometrical > calculation.  I know there are those that disagree.  I don''t > understand > their perspective.  Do they think the "rotate" command is an > unnecessary > abstraction because we have multmatrix?   Would they really prefer to > do the > trig to orient a cylinder onto a face of a dodecahedron instead of > having it > done for them?  But the original poster seemed interested in a more > abstract > approach.  I'm just pointing out that such an approach is possible. Such an approach is possible (sometimes) if you can query existing objects for their geometry, and you can't do that in OpenSCAD. Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 In reply to this post by nophead On 9/5/2019 3:16 PM, nop head wrote: >I think the idea that you should use trig every time you want to position an object is absurd.    Well for me trig is trivial but I have no idea what that BSOL code does, or how it works. I would have to look it up but I know what atan2 does. Yeah, that's pretty much my attitude too.  I know the trig, more or less; I'd have to learn the library.  It means I reinvent wheels, but sometimes reinventing a wheel is easier than trying to understand how somebody else's wheel works. You can make it a little simpler (in some ways) by embedding the rotation and translation in the "parent" object and applying them to children.  In a couple of cases I've had models with "faceplates" on which there are controls; the design I've used is to accept a child that contains objects that are to be placed on the faceplate.  The child objects - knobs and whatnot - are laid out as if they were on a horizontal surface at z=0; the parent rotates and translates them into the right place. That's basically the "attachment" model that some libraries support, but without any attempt at generalizing. On these models of a washing machine and a drier, the control panel (with the buttons and knobs) and the detergent door (on top of the washer) are done this way.  Partly it makes it easier to think about the layout, but also the basic box for the two is the same module; it's only those two add-ons that are specific. I don't remember why one of the controls on the drier is white. I've used similar strategies for positioning handles on cabinets, separating the design of the handle from the positioning (and duplication!) on the cabinet. More than you wanted to know. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 Basically what you're describing below is heading towards the attachment functionality implemented in the various libraries.  You can of course write it all yourself, which saves you the trouble of learning to use the library, I guess.   The notion that everybody should write their own personal libraries has some proponents in this forum, I think because people believe it will be easier to write their own code than learn how to use libraries written by others.   jim_klesseg wrote: > In your original case of placing a feature perpendicular to the face of an > extruded polygon, one way is to work it backwards. > > Orient your polygon  so that it is on the xy plane, and your segment (soon > to be face) is on the x axis, and then extrude in the z axis for your > extrusion and then make your other object extend out in the "y" direction. > Then manipulate the new combined object as needed to get the face where > you want it. > I guess it would be relatively simple to make a module that took an n > sided polygon and allowed you to place one of "n" objects perpendicular > to a face. you would still need to know where you want them in z and y, > which could be more vector inputs to the module. -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

Open this post in threaded view
|

## Re: How to make a cylinder perpendicular to a sloping face

 In reply to this post by Robin2 I have this same "position object on a face" code; here is my solution that I use in my own code (only works for slopes in one direction: // -------------------------------------------------------------- module onFace(height1, height2, depth, x = 0, y = 0, z_adj=0) {     // Given Parameters of a sloped face defined in (x,y) and rising in Z, place children on sloped face     //      height1 = height of front edge     //      height2 = height of rear edge     //      length  = length of between front and rear     //       x      = offset positioning in x (optional)     //       y      = offset positioning in x (optional)     //       z_adj  = fudge factor     //      { ... } = children to be positioned     slope = (height2 - height1) / depth;     face_angle = (slope != 0 ? (atan (slope)) : 0);         // Optional Printing of calculated angle     //echo ("module onFace(): Face Angle=", face_angle);     translate ([0, 0, z_adj])     {         translate ([x, cos(face_angle) * y, height1 + sin(face_angle) * y])             rotate ([face_angle, 0, 0]) children();         } // end translate             }   // end onFace() // --------------- Sample Code --------------------- h = 40; d = 30; w = 20; // Make thing rotate ([90, 0, 90]) linear_extrude (w) polygon (points=[[0, 0], [d, h], [d, 0]]); // Place items on face onFace (height1=0, height2 = h, x=w/2, y=15, depth = d) cylinder (d=10, h=20); onFace (height1=0, height2 = h, x=w/2, y=35, depth = d) cube (5); -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
 In reply to this post by Robin2 On 9/10/19 3:13 AM, Robin2 wrote: I have had both good and bad experiences with libraries (unrelated to ```Openscad). Unfortunately people who write OpenSource code seem very unlikely also to support the code with good documentation. I have wasted a lot of time trying (and failing) to figure something out probably because I had a mistaken image of what the library was intended to do. The more complex the library the greater is the need for documentation. ``` This also speaks to the complexity of libraries people tend to write for OpenSCAD, which I think is related to lack of traction for any given package manager. Because there's no commonly accepted package manager, everyone's pet library tends to start from zero and then grows in scope to become something worth sharing.  Consequently, every library includes (and should document) a lot of fairly fundamental constructs, each with their own quirks and limitations.  Nobody "builds on the shoulders of giants," so to speak, and they only ever get built so high. Further, the lack of a canonical, versioned package manager makes everyone hesitant to make breaking changes to the libraries - which keeps other contributors from helping take the sharp edges off. Combined, it all makes for bigger libraries that are harder to document well - while needing the documentation more. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org