# Anyone up for a little trigonometry on a Sunday?

Anyone up for a little trigonometry on a Sunday? I like to make a fillet in OpenSCAD for the area in the image. Essentially I have broken it down into finding point x,y with the variables on the picture known.

Its not even trig. Some basic algebra will solve this.
I’m assuming a,b,r1,r2,and h2 are all known values.
Call your horizontal line the origin, so, y == r1
The distance between (x,y) and (a,b) is sqrt((x-a)^2 + (y-b)^2)
That distance is also equal to r1 + r2
so we can say:

r1 + r2 = sqrt((x-a)^2 + (y-b)^2)

now, x is the only unknown value in that equation so we throw some algebra at it and solve for x

square both sides and we get

(r1 + r2)^2 = (x-a)^2 + (y - b)^2

subtract (y-b)^2 from both sides

(r1 + r2)^2 - (y-b)^2 = (x-a)^2

take the square root of both sides:
sqrt((r1+r2)^2 - (y-b)^2) = (x-a)

sqrt((r1+r2)^2 - (y-b)^2) + a = x

from earlier we know that y = r1

y=b-r2-r1+h2; (a-x)^2+(b-y)^2=(r1+r2)^2; x=a-sqrt((r1+r2)^2-(b-y)^2);

Thank you both. I was messing around with tangents. A bit late in my part of the world. Will check it out tomorrow.

thanks for this interesting fact.

I like this thread, it say’s this is a community…

I propose to use a CAD Software instead of unfinished alpha software, select that edge and the fillet tool. Done.

I like OpenSCAD, gets me where I wan’t and models are highly parametric an reusable. Sometimes the limits and constraints of a tool is what makes it fun.

Someone found me this a while ago. Since then I have slowly changed mo models to implement it.

Check out my x-ends on github to see how it is used.

Extract:
My guess is there are three main ways that people find it best to do drawings.

There are artists who I should imagine are few and far between who can get just any medium and any paper and create something.

Then I should imagine there are others who took to technical drawing and find the software packages which are loosely based on the original concept of drawing lines on a technical drawing board the best way to create things.

Then there is probably another group of people like myself who find programming itself interesting and relatively easy and this is how open scad works. Basically you write a line of code which tells the program to draw, say a cube on the screen and if you want the cube to be hollow (like an open box) then the hollow is actually another cube which is removed from the initial cube.

I’ve already implemented that kind of curves with openscad in this thing:

Chek the cc_curve() module (concave - convex curve)

Thank you @Juan_Gonzalez_Gomez I will look into it. The thing looked like an interesting piece btw.

@Marcus_Wolschon
OpenSCAD is purely CSG so I guess adding a fillet command would go against its purpose. Even when FreeCAD was in alpha state it did support fillets and chamfers. But this may depend on the geometric kernel the app is based on. Does CGAL even support this? In some ways it is so limited compared to a true CAD B-rep geometric kernel… OpenSCAD is really a very odd beast, in its own separate universe.

Does OpenSCAD even have any notation to select an edge or 2 faces in a stable way to do an operation on?

Finally had time to wrap my head around this. Here is my final soultion.

/* Creates a fillet to a cylinder
h = z height
dy = fillet y edge above baseline
F = correction for floatingpoint error
*/
module filletForCylinder(r,h,dy,rc,F=0.01, center=false, \$fn=\$fn) {
translate([0,0,center ? -h/2 : 0])
difference() {
translate([(cos(asin((dy+r) / (r+rc)))*rc)-F,dy-F,0])
cube([sqrt(pow(r + rc,2) - pow(dy+r,2))-(cos(asin((dy+r) / (r+rc)))*rc)+F,sqrt(pow(rc,2)-pow((cos(asin((dy+r) / (r+rc)))rc),2))-dy+F,h]);
translate([sqrt(pow(r + rc,2) - pow(dy+r,2)), r+dy, -F]) cylinder(r=r, h=h+2
F);
}

}

%cylinder(r=20, h=10);
%translate([0,-10, 0]) cube([40,20,10]);
for(i=[0,1])
translate([0,0,5]) rotate([180*i, 0, 0]) filletForCylinder(r=14,h=10,dy=10,rc=20, center=true);

@Marcus_Wolschon The 3D model view in OpenSCAD is for visualization purposes only, nothing is selectable. There is no concept of edge or face selection since you cannot select anything. The only interaction is with the console, typing commands. You need to “compile” to refresh the view. To anyone with “real” CAD experience this is totally baffling and counter-productive, but there you go.

I wasn’t thinking about a graphical selection.

You can’t do it programmatically either. You would need to calculate where the edge or face is, then do what you need. Whats worse is that you can’t lookup the location and dimension of an object, it must be stored in a variable. And you can’t assign a variable to itself, so no x=x+1 or the like.
Its probably the worst 3d cad software out there, second to MS paint.
I’m tempted to put up a bounty for someone to make a real programming based offline 3d cad software.

The size and location of objects in openSCAD is defined by the user. Hanging on to the values you gave it is easy if that’s important to you. Practicing good code design will help make using it less frustrating but there’s no way around doing a little math if you want to do anything very complicated. It’s not for everyone or every design but I for one like openSCAD very much. You might prefer coffeeSCAD. Yes, it runs in browser but you don’t need to be online to use it. There are other CSG languages out there so there may be another one you’d prefer more. Also, many are open source so if you have ideas as to how they could be better, roll up your sleeves…

@Stephanie_A
Did you know that FreeCAD can be used from the console with Python, a complete and well-known programming language? All GUI commands can be called from the console. Complex parametric scripting can be accomplished, and FreeCAD is based on a “real” CAD kernel, Open Cascade. Although I read someone complain that it takes a lot more lines of code to do the same thing than OpenSCAD. Not for fillets though!