Squircle

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
leoheck
Veteran
Posts: 1225
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Squircle

Post by leoheck »

Hello guys!

I have no idea how to create a squircle*.
Anyone has an idea on how to do this with a sketch?

* Squircle Reference
https://en.wikipedia.org/wiki/Squircle

Or even better, how can I create a box with all corners with this shape instead of fillet.
Toughts?
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Squircle

Post by TheMarkster »

These squircles are precise parametric curves. We can produce them with the following macro code:

Code: Select all

import FreeCAD
from math import *
import Draft

if not App.ActiveDocument:
    App.newDocument()

r = 10
s = 2

wirePoints=[]

for ii in range(0,628):
    t = ii/100.0
    p0 = (r/(2*s))
    p1 = sqrt(abs(2+2*s*sqrt(2)*cos(t)+s**2*cos(2*t)))
    p2 = sqrt(abs(2-2*s*sqrt(2)*cos(t)+s**2*cos(2*t)))
    p3 = sqrt(abs(2+2*s*sqrt(2)*sin(t)-s**2*cos(2*t)))
    p4 = sqrt(abs(2-2*s*sqrt(2)*sin(t)-s**2*cos(2*t)))
    x = p0*p1-p0*p2
    y = p0*p3-p0*p4
    wirePoints.append(FreeCAD.Base.Vector(x,y,0))

Draft.makeBSpline(wirePoints)
The "s" value in the above code defense (Edit: defines) the squareness or roundness of the shape. s=0 gives us a perfect circle (except we can't use s=0 or we get divide by zero error, so we can use something like s = 0.001). s=1 gives up a square. In the image below I used different s values between 0 and 1 to produce the various curves. The green one in the middle was produced with s=2.

The r value is the radius.
squircles.png
squircles.png (26.46 KiB) Viewed 1337 times
In the attached freecad file each of the bsplines is named according to the s value used to create it. For example, BSpline_s0_9 was produced with s=0.9.

If you wanted to make a box one way would be to extrude one of the profiles in the x, y, and z directions. Extrude, make copy, rotate the copy 90 degrees along the x axis. Extrude the copy, make another copy. Extrude that copy after rotating it 90 degrees on the y axis. Take the common of all 3 extrudes. All 3 extrudes should be symmetrical and long enough that each one sticks out along its extruded direction. When I did this I had to move on the extruded objects by 1 nanometer in the x,y, and z directions or else the common operation failed due to coplanar edges, I guess.

To extrude on of the bsplines make sure its closed property is set to true.
Attachments
squircle3d.png
squircle3d.png (35.89 KiB) Viewed 1337 times
squircle.FCStd
(1006.53 KiB) Downloaded 28 times
Last edited by TheMarkster on Fri Jul 12, 2019 2:11 am, edited 1 time in total.
leoheck
Veteran
Posts: 1225
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: Squircle

Post by leoheck »

TheMarkster, thanks for teaching me this thecnique and also for the explanation, this was great. And also thank you for sharing the freecad model.
leoheck
Veteran
Posts: 1225
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: Squircle

Post by leoheck »

TheMarkster, I am playing here with the file you shared, and I see that one of its corners is not well-formed like the others. Do you have any idea on how to fix it?
Attachments
Screenshot-20190711203149-611x497.png
Screenshot-20190711203149-611x497.png (8.88 KiB) Viewed 1198 times
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: Squircle

Post by chrisb »

TheMarkster wrote: Wed Jul 10, 2019 3:38 am squircle3d.png
It's not a squircle, it's a sphubic :lol: .
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
leoheck
Veteran
Posts: 1225
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: Squircle

Post by leoheck »

How did you do to extrude creating a solid? Freecad is complaining that it is not a closed object.

Edit: Oh, you already told that!
To extrude on of the bsplines make sure its closed property is set to true.
leoheck
Veteran
Posts: 1225
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: Squircle

Post by leoheck »

I was able to reproduce your shape, it is awesome. The issue I saw is that the intersection didn't work properly, I guess. Then I moved the objects 0.01 mm to the direction of each extrusion and I was able to make the common from all the shapes. (Maybe this is also something you said but I couldn't understand properly). But AWESOME. This new shape is actually something good without the strange corner that I saw before.
Attachments
Screenshot-20190711203149-611x497_2.png
Screenshot-20190711203149-611x497_2.png (86.71 KiB) Viewed 1188 times
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Squircle

Post by TheMarkster »

Another attempt, this time using curved shapes workbench. With this tool one of the shapes is the profile. The other 2 act as boundaries. The original profile gets resized according to the boundary shapes as it is arrayed. I don't like the squared off ends I end up with, but I think it's an improvement. I tried using the small profiles at the ends, but I didn't like how that lofted either. It might be possible to split with a plane one of the good sides and polar array the good side around 4 times to end up with a nicer looking model.

phpBB [video]
Post Reply