Sketcher scaling of curve

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
ericho852
Posts: 5
Joined: Thu Jun 14, 2018 10:47 am

Sketcher scaling of curve

Post by ericho852 »

Hi all,
I am currently working on sketcher workbench. In some case, I would like to create a curve (not a arc or circle). In this curve, I would like to have its shape predetermined and use the spreadsheet value to constraint its curve length. So that I can produce the similar curve when I change the independent factor in spreadsheet.

Please help if there is any function to constraint the length of a curve. I am exploring the B-spline function. But it seems not having the length constraint property.

Thank you very much.


OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13522 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 3bb5ff4e70c0c526f2d9dd69b1004155b2f527f2
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/UnitedStates (en_US)
Attachments
troubleshoot sample.FCStd
For example, I would like to determine the teardrop shape and reproduce similar teardrops of different size with spreadsheet function
(18.1 KiB) Downloaded 92 times
troubleshoot printscreen 3.png
troubleshoot printscreen 3.png (139.02 KiB) Viewed 1319 times
User avatar
meme2704
Veteran
Posts: 2926
Joined: Sat Apr 01, 2017 2:47 pm
Location: Vosges

Re: Sketcher scaling of curve

Post by meme2704 »

hello
I believe that this is not possible since the principle of a B-spline is to have a starting point, a point of arrival and to pass "at best" by points of constraint, with arcs of tangencies
If you give it a length too long, it floats like an old clothesline according to the wind, if you do it too short, it will join the constraint points by more stretched segments and sharp angles at points of constraint
oldmachine
Posts: 243
Joined: Wed May 31, 2017 11:49 pm

Re: Sketcher scaling of curve

Post by oldmachine »

... Agreed - not possible (ASFIK).

Consider making your curve from combinations of Radius' and lines. If dimensioning them, you may have a better chance of figuring out something useful in a spreadsheet - perhaps, also curves defined by second and third-order equations but, it won't be simple.

The headline say's "scaling a curve" - if scaling is what you want, you could make a macro (from Recording your steps) and using the Draft workbench's 'Scale' tool. Example below shows using a B-spline scaled up and down... The 'Scale' tool's input panel takes a bit of understanding by trying it out ( Tip: don't move the mouse/cursor, just hit the Enter Key 3 times to accept zero's and get to next panel where you select scaling/uniform...
MAC OSX Sierra
3D Parts & Links (made using FreeCad and Solidworks): https://www.thingiverse.com/Still_Breathing/designs
Android App & Links: https://play.google.com/store/apps/deta ... .bestknots
UR_
Veteran
Posts: 1355
Joined: Tue Jan 03, 2017 8:42 pm

Re: Sketcher scaling of curve

Post by UR_ »

I'm not sure, if i understood your question correctly, but if you need a bspline of same shape as your template, but with a defined length, one could do this by python.

- load your file
- execute "macro scale.FCMacro"
- as result you will get an object from same shape, but with Length = 300 mm

Code: Select all


TemplateCurve = App.getDocument("troubleshoot_sample").getObject("Sketch")
TemplateLength = TemplateCurve.Shape.Length 

DesiredLength = 300.


myScaledCurve = TemplateCurve.Shape.copy()
myScaledCurve.scale(DesiredLength / TemplateLength)
Part.show(myScaledCurve)

print ("new Length", myScaledCurve.Length)

scaled to defined length.png
scaled to defined length.png (12.86 KiB) Viewed 1288 times

File:
troubleshoot sample_ur.FCStd
(19.11 KiB) Downloaded 90 times

Done with:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13892 (Git)
Build type: Release
Branch: master
Hash: 23f58f1afc710c6189ac44414c8696e8e838535c
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: German/Germany (de_DE)
oldmachine
Posts: 243
Joined: Wed May 31, 2017 11:49 pm

Re: Sketcher scaling of curve

Post by oldmachine »

... I found this link for an older release of FreeCAD. I uses equations to define a parametric curve - perhaps a useful notion to explore...
https://www.youtube.com/watch?v=DZb7z5HKU6k
MAC OSX Sierra
3D Parts & Links (made using FreeCad and Solidworks): https://www.thingiverse.com/Still_Breathing/designs
Android App & Links: https://play.google.com/store/apps/deta ... .bestknots
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Sketcher scaling of curve

Post by TheMarkster »

Can be done, but is somewhat tedius.

Create a construction mode circle roughly in the center of the teardrop. Constrain horizontally and vertically the center of the new circle to each of the 5 control points. (Might want to temporarily constrain the control points to the origin temporarily so they don't move before this step.)
Constrain the center of the new circle to the origin vertically and horizontally. You should have 12 constraints (6 horizontal and 6 vertical), 2 for each of the 5 control points to the center point and the 2 for the center point to the origin.

Create your spreadsheet, and assign an alias called scaleFactor to one of the cells and put 1.0 in it for now.

Edit the lock constraints for the 5 control points and for the center point such that they would now be:

Spreadsheet.scaleFactor * nnn (where nnn is the current value, whatever it already is for each constraint)

Attached is a file where I did something similar to this with the unnecessary added step of a construction mode circle with its radius named baseRadius, with it being used as a scale factor and with its radius constrained to the spreadsheet. Could easily do without this middleman though.

The teardrop will move with changes in scaleFactor with this setup, but you could constrain the center point directly to the origin instead of using the spreadsheet scaleFactor for its position.

I believe the teardrop will maintain its aspect ratio through various scales. Probably the closer to the center you can put the center circle the better this will work. If you average all the x,y coordinates of the 5 control points and use that to position the center it will probably work best.
Attachments
troubleshoot sample2.FCStd
(18.43 KiB) Downloaded 91 times
ericho852
Posts: 5
Joined: Thu Jun 14, 2018 10:47 am

Re: Sketcher scaling of curve

Post by ericho852 »

Thank you for your help. I think I will try your methods to construct the graph. Although it somehow looks tedious, the product is what it really matters. Thank you

TheMarkster wrote: Mon Jun 18, 2018 6:40 pm Can be done, but is somewhat tedius.

Create a construction mode circle roughly in the center of the teardrop. Constrain horizontally and vertically the center of the new circle to each of the 5 control points. (Might want to temporarily constrain the control points to the origin temporarily so they don't move before this step.)
Constrain the center of the new circle to the origin vertically and horizontally. You should have 12 constraints (6 horizontal and 6 vertical), 2 for each of the 5 control points to the center point and the 2 for the center point to the origin.

Create your spreadsheet, and assign an alias called scaleFactor to one of the cells and put 1.0 in it for now.

Edit the lock constraints for the 5 control points and for the center point such that they would now be:

Spreadsheet.scaleFactor * nnn (where nnn is the current value, whatever it already is for each constraint)

Attached is a file where I did something similar to this with the unnecessary added step of a construction mode circle with its radius named baseRadius, with it being used as a scale factor and with its radius constrained to the spreadsheet. Could easily do without this middleman though.

The teardrop will move with changes in scaleFactor with this setup, but you could constrain the center point directly to the origin instead of using the spreadsheet scaleFactor for its position.

I believe the teardrop will maintain its aspect ratio through various scales. Probably the closer to the center you can put the center circle the better this will work. If you average all the x,y coordinates of the 5 control points and use that to position the center it will probably work best.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Sketcher scaling of curve

Post by TheMarkster »

I had another idea you might want to consider. Instead of setting the 5 control points' constraints to the spreadsheet, set them to a cube instead. The cube's length would be the scale, the height and width the x,y position of the central circle. This will do 2 things:

1) you can interactively control the scale and position of each teardrop just by modifying the control cube's length,width, and height properties in the data tab of the combo view.
2) you can duplicate Sketch and Cube (to Sketch001 and Cube001) and use this macro to reassign the constraints in Sketch001 to Cube001 (from Cube).

Code: Select all

import FreeCAD

selection = FreeCADGui.Selection.getSelectionEx()
for s in selection:
    obj = s.Object #obj is the sketch object
    label = obj.Label #will be something like 'Sketch001'
    if label == 'Sketch':
        continue #we don't want to modify the original sketch
    base = label[:6] #should be 'Sketch'
    extension = label[6:]+'.' #should be, e.g. '001.'
    if base != 'Sketch':
        continue #we don't want to try to modify any non-sketches inadvertently selected
    exp = obj.ExpressionEngine #contains our constraints we need to modify to point to the new control cube

    for ii in range(0,len(exp)):
        if exp[ii][0] and exp[ii][1]:
            conString0 = exp[ii][0] #e.g. 'Constraints[14]'
            conString1 = exp[ii][1].replace('Cube.','Cube'+extension) #renames ,e.g. '1.77 * Cube.Length' to '1.77 * Cube.001.Length'
            if 'Cube' in conString1:
                obj.setExpression(conString0,conString1) #replaces existing constraint with this new one

App.ActiveDocument.recompute()
To duplicate the Cube/Sketch duo select them and use the Edit menu -> Duplicate Selection tool to create copies of them. Or (on Windows) select the Sketch and Cube, Ctrl+C, then Ctrl+V (Ctrl+V as many times as you like for as many copies as you like). The next step is to select all the Sketches (but not the original Sketch, just Sketch001, Sketch002, etc.) and run the macro with them selected. Now you can control each teardrop by changing the properties of the control cube for that sketch.

In the attached file I have made 5 copies of the Sketch/Cube duos and set each cube's length property to its name extension, example Cube003 has length = 3, which scales the associated teardrop (Sketch003) to scale factor of 3.

If you want to use a spreadsheet you can just assign the cube's height,width,length properties to cells in the spreadsheet. Cube001 length, for example, could be to B1, Cube005 height to C5, Cube005 width to D5. You would need to manually change each cube's property to set it to the correct cell in the spreadsheet, but if you use a naming convention similar to what I suggest, it would be relatively straight forward to do. You can also maybe modify the macro to handle this operation, too.

The cubes, of course, can be made invisible. Select in the combo tree view and press the spacebar to hide/unhide.

Disadvantage to this (it just occurs to me) is you can't position with negative numbers because you can't have negative width or negative height. You could modify the constraint formulas to take this into account or consider using Wedges, which have more properties to use and which said properties can include negative values. Wedges can be created in Part workbench. Part menu -> Create Primitives -> Wedge. Each wedge has multiple X, Y, and Z properties which define the absolute positions of the vertices. For example, you could use Xmin and Ymin for the center circle's x,y position and Zmin for the scale. And you would still have other properties to use for other purposes. I've hardcoded 'Cube' into the macro, but this is easily circumvented by simply giving the first Wedge the label 'Cube' or my modifying the macro.

Edit: Now it occurs to me Wedges could be problematic because some properties cannot exceed other properties, e.g. ZMin cannot exceed ZMax or else you get an invalid object. Maybe is better to just stick to the cubes and use some really big number for width and height, then subtract that value in the constraint formula. Example: set Cube height to 10000 and let the constraint for the central point's y position be something like Cube.Height-10000. This would let you safely position the teardrop to negative y location and yet still leave you with a valid cube object.
Attachments
cubes-controlling-sketch-constraints.png
cubes-controlling-sketch-constraints.png (108.35 KiB) Viewed 1208 times
troubleshoot sample3.FCStd
(35.22 KiB) Downloaded 83 times
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Sketcher scaling of curve

Post by TheMarkster »

You could, of course, use placement to position the various teardrops, too.
cubes-controlling-sketch-constraints2.png
cubes-controlling-sketch-constraints2.png (141.97 KiB) Viewed 1199 times
In this image I have some 3D teardrops positioned and scaled to appear like rain drops. It's raining blood! :o I drew a line from the center circle to the top control circle and used it as the axis of revolution in Part workbench, made several copies of the revolution/cube duo, expanded the revolutions in the tree and selected the sketches, and ran the macro on the selected sketches. Then it was a matter of adjusting the scale via the cube length property and placements of the revolutions.
Post Reply