Edge intervals in a solid

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
revintage
Posts: 5
Joined: Sun Apr 08, 2018 10:45 am

Edge intervals in a solid

Post by revintage »

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6712 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: da2d364457257a7a8c6fb2137cea12c45becd71a
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17

Hi,

Without knowledge in 2D nor 3D, this is my learning project. Will route a mould for a 50kg keel bulb for my sailboat. Will import the 3D file into a simple CNC-program called Vectric Aspire. Importing a 3D works fine, so no problem there.

Started in “Part” where I made 29 ellipses combining data from two different NACA profiles. Then I input them like parametric primitives placing them apart in Z. Used Loft to generate a solid and it looked good until I zoomed the leading edge.

Not smooth enough for me as a NACA profile always begin with a radius and the solid is pointed. Maybe I am picky, but this is also learning.

In the solid, the Z line “edge2” is made up by straight lines in 2mm intervals. How to I adjust this to smaller intervals? I have used the python console to calculate volume so a command line would work.

Not sure this is the way to go? Is there a better way to make “edge2” a curved line? Bezier?
Attachments
bulb4solid.FCStd
(38.07 KiB) Downloaded 35 times
prtsolid.png
prtsolid.png (236.27 KiB) Viewed 1657 times
xhb5.xlsx
NACA input data
(10.69 KiB) Downloaded 29 times
bulb4ellips.FCStd
(16.69 KiB) Downloaded 31 times
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Edge intervals in a solid

Post by wandererfan »

I think you will have to loft around the circumference instead of along the axis to avoid a sharp point or flat surface at the end.
Is this what you're looking for?
revintage_longLoft.png
revintage_longLoft.png (15.8 KiB) Viewed 1646 times
I added a column to your data for a point midway between minor and major axis points, created 3 wires from the data, then lofted from wireMinor to wireMid to wireMajor, then mirrored the result 3 times.

There is one wonky data point that causes a bulge in the shape.
Attachments
xhb5_mid.csv
(560 Bytes) Downloaded 39 times
CSVtoBSpline.py
(728 Bytes) Downloaded 47 times
revintage_longLoft.fcstd
(79.83 KiB) Downloaded 34 times
revintage
Posts: 5
Joined: Sun Apr 08, 2018 10:45 am

Re: Edge intervals in a solid

Post by revintage »

Thanks for helping, wandererfan!

Just realized I did choose a little to advanced learning project :oops: . When I see your neat solution to the problem, I understand I have a long way to go. It might even turn my grey hair to white ;) .

This is exactly what I was looking for. Exported a 3D-file into Aspire and everything was just like it should, except for the unwanted bump. You can split, rotate and invert(for making a mould) when importing into the router program, so importing the complete bulb gives you all what you need.

Correct, it was a typo in row 23 in the .csv, should be 49.7 instead of 59.7. No wonder there´s a bump. When interpolating, D23 should probably be changed to 27.0 . Returning the hopefully correct .csv .

Not having the mathematical skills to calculate the 45 degree radius of an ellipse in the added column in the .csv, just curious what equation you are using?

Tried to modify the CSVtoBSpline.py and placed it in: C:\Program Files\FreeCAD 0.16\bin , but can´t make it work. Changed the line:

fileSpec = "/home/huxster/Documents/CAD/Complaints/xhb5_mid.csv" to: fileSpec = "C:\Users\Lars\Desktop\freecad\xhb5_mid.csv". See attached file.

Maybe I am far out, but after checking the manual I thought you should just run "import" of the CSVtoBSpline.py into the Python console to make it run. Surely it must be the wrong commando as I can´t make it work. This is what I get back:

>>> import CSVtoBSpline.py
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\FreeCAD 0.16\bin\CSVtoBSpline.py", line 11, in <module>
f=open(fileSpec,"r")
IOError: [Errno 22] invalid mode ('r') or filename: '\\C:Users\\Lars\\Desktop\x0creecad/xhb5_mid.csv'
>>>



Brgds
Lars
Attachments
CSVtoBSpline.py
(719 Bytes) Downloaded 30 times
xhb5_mid.csv
(539 Bytes) Downloaded 31 times
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Edge intervals in a solid

Post by wandererfan »

revintage wrote: Mon Apr 09, 2018 12:00 pm This is exactly what I was looking for. Exported a 3D-file into Aspire and everything was just like it should, except for the unwanted bump. You can split, rotate and invert(for making a mould) when importing into the router program, so importing the complete bulb gives you all what you need.
Great. Glad it works for you. Looks nicer without the bump.
revintage_longLoft_rev.png
revintage_longLoft_rev.png (167.05 KiB) Viewed 1602 times
revintage wrote: Not having the mathematical skills to calculate the 45 degree radius of an ellipse in the added column in the .csv, just curious what equation you are using?
The full details are here:
https://math.stackexchange.com/question ... n-an-angle, but we can simplify a bit because tan(45) = 1.
revintage wrote: fileSpec = "/home/huxster/Documents/CAD/Complaints/xhb5_mid.csv" to: fileSpec = "C:\Users\Lars\Desktop\freecad\xhb5_mid.csv". See attached file.

Code: Select all

fileSpec = "\C:Users\Lars\Desktop\freecad/xhb5_mid.csv"
I think your fileSpec needs revision to this:

Code: Select all

fileSpec = "C:Users\Lars\Desktop\\freecad\xhb5_mid.csv"
"\f" is an escaped formfeed so you need double "\" and you have a linux style "/" between freecad and xhb5.

I usually run my Py routines from the Macro toolbar, not the console, so I'm no help with importing.
Attachments
revintage_longLoft_rev.fcstd
(43.76 KiB) Downloaded 28 times
revintage
Posts: 5
Joined: Sun Apr 08, 2018 10:45 am

Re: Edge intervals in a solid

Post by revintage »

Valuable information, thank you!

I actually ran it both from the Macro toolbar and bin, but with the same result. Easier to edit in the Toolbar.

I also tried the Filespec you recommended, before I answered, but it didn't work either way. Another message though:

Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: invalid \x escape

Does this tell you anything, could it it be another Linux/Windows related problem? Shorter message anyway.

Did an export/import of your "longLoft_rev" using .stl to Aspire. Unfortunately strange things happens. Must have to with the D-column.

Seems to be tricky one, as the cross section is not elliptical as the "quarters" should be 90 degree where they meet.

I'd really like to get this working, as it will be a great tool for bulb design. After this something more basic ;) .

Would be a defeat to have, to go back to my initial part and smooth it in Aspire.

Brgds
Lars
Attachments
Newside.pdf
(119.4 KiB) Downloaded 45 times
bulbnew.pdf
(261.91 KiB) Downloaded 53 times
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Edge intervals in a solid

Post by wandererfan »

There's an error (careless cut & paste) in the script that leaves a hole at the large(bow?) end.

Code: Select all

for l in lines:
is the correction. THe original version was skipping the first line of data.

The last line in the data is odd to me also. An ellipse wouldn't have a zero radius and a non-zero radius so the calculation of the midpoint will be wrong. That could be causing problems at the flat(stern?) end.

As for the filespec, I'm told that forward slashes will work in Python on Windows, so you could code your spec as "C:Users/Lars/Desktop/freecad/xhb5_mid.csv" and it should work. Putting backwards slashes in Python file names is apparently a bad idea.
revintage
Posts: 5
Joined: Sun Apr 08, 2018 10:45 am

Re: Edge intervals in a solid

Post by revintage »

OK,
IRL I made the first station an ellipse 10um, 10um and the last one 14.8mm, 1mm ;-).. Otherwise my ellipse-stapling didn´t work. Attach the adjusted xhb, where I don´t know what D29 should be. But I suppose your solution should begin with 0, 0.

I couldn´t make it work this time either, but a new error message:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\FreeCAD 0.16\bin\CSVtoBSpline.py", line 6
import FreeCAD
^
IndentationError: expected an indented block

I might have missunderstood you about the correction, attach the script I now have.

Could you please make another double check and return a corrected .py to me.
Attachments
xhb5_mid.csv
(539 Bytes) Downloaded 31 times
CSVtoBSpline.py
(734 Bytes) Downloaded 28 times
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Edge intervals in a solid

Post by wandererfan »

I think this might be it!
again2.png
again2.png (10.45 KiB) Viewed 1504 times
I used 5 splines this time to keep the connections between quarters to tangents. You'll want to check my stora/lilla numbers. The tail is still open a bit.
Attachments
again216.fcstd
(119.27 KiB) Downloaded 35 times
CSVtoBSpline.py
(995 Bytes) Downloaded 37 times
again2.xlsx
(11.54 KiB) Downloaded 31 times
again2.csv
(2.32 KiB) Downloaded 32 times
revintage
Posts: 5
Joined: Sun Apr 08, 2018 10:45 am

Re: Edge intervals in a solid

Post by revintage »

Good thinking to usmore BSplines. Takes the guesswork out the loft function.

Imported your 216 into Aspire and it looks even better now. But very pointy at the sides in the most rear part of the bulb.

Might be even better to choose even more BSplines to get the ellipises better defined (my guess)? Must the 90 degree be equally parted, like
11.25 22.5, 33.75 45 56.25 67.5 78.75?
Or can one add random angles like
5 10 22.5 45 67.5 80 85? Problems seem to bigger, the closer you get to 0 and 90 degrees.

Actually this seems to be more of a mathematical matter, where everything must be correctly defined in the inital *.xlxs file.

Still the .py doesn´t work.

This makes me think Windows and Freecad aren´t real friends.
This is the latest error:

>>> import CSVtoBSpline(12).py
File "<input>", line 1
import CSVtoBSpline(12).py
^
SyntaxError: invalid syntax
>>>

What do I do wrong :roll: ?

Below is copied from my .py file where only the fileSpec is altered. Compared to the one you sent I can´t find any discrepancies:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 3d csv file to points list to 5 DWires
import FreeCAD
import Part
import Draft

fileSpec = "C:\Users\Lars\Desktop\freecad\again2.csv"
#majX,minX,22.5x,22.5y,45xy,67.5x,67.5y,z
#0 ,1, ,2 ,3 ,4 ,5 ,6 ,7
f=open(fileSpec,"r")
lines=f.readlines()
f.close()
pts_0 =[]
pts_90 =[]
pts_225 = []
pts_45 = []
pts_675 = []
for l in lines:
lsp=l.split(',')
p0=FreeCAD.Vector(float(lsp[0]),0.0,float(lsp[7]))
p90=FreeCAD.Vector(0.0,float(lsp[1]),float(lsp[7]))
p225=FreeCAD.Vector(float(lsp[2]),float(lsp[3]),float(lsp[7]))
p45 =FreeCAD.Vector(float(lsp[4]),float(lsp[4]),float(lsp[7]))
p675 =FreeCAD.Vector(float(lsp[5]),float(lsp[6]),float(lsp[7]))
pts_0.append(p0)
pts_90.append(p90)
pts_225.append(p225)
pts_45.append(p45)
pts_675.append(p675)
dw1 = Draft.makeBSpline(pts_0)
dw2 = Draft.makeBSpline(pts_225)
dw3 = Draft.makeBSpline(pts_45)
dw4 = Draft.makeBSpline(pts_675)
dw5 = Draft.makeBSpline(pts_90)

Brgds
Lars
User avatar
wandererfan
Veteran
Posts: 6309
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Edge intervals in a solid

Post by wandererfan »

revintage wrote: Wed Apr 11, 2018 12:55 pm Might be even better to choose even more BSplines to get the ellipises better defined (my guess)? Must the 90 degree be equally parted
More splines would make for a better fit to the ellipse. I don't know of any requirement for the splines to be equally spaced.
revintage wrote: Still the .py doesn´t work.
...
>>> import CSVtoBSpline(12).py
File "<input>", line 1
import CSVtoBSpline(12).py
^
SyntaxError: invalid syntax
>>>
are you trying to import the py file into the FC Python console? if so, the import should look like this:

Code: Select all

>>> Gui.ActiveDocument=Gui.getDocument("Unnamed")
>>> import CSVtoBSpline
>>> 
I usually run my Py scripts as macros, not from the console.
revintage wrote: Below is copied from my .py file where only the fileSpec is altered. Compared to the one you sent I can´t find any discrepancies:
There is something odd about the indentation in the "for l in lines" loop. If you are using Tab characters for indenting, try using spaces instead.
Your version works fine here once the indentation error is fixed.
Post Reply