Curves workbench

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!
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

@keithsloan52

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("IsoCurve")
ob, fa = obj.Face
face = getattr(ob.Shape, fa[0])
surf = face.Surface
umin, umax, vmin, vmax = sub.ParameterRange
nu = obj.NumberU
ulist = [i*(umax - umin)/nu + umin for i in range(nu+1)]
nv = obj.NumberV
vlist = [i*(vmax - vmin)/nv + vmin for i in range(nv+1)]
boxLength = 2
cmpd = doc.addObject("Part::Compound","CompoundBoxes")
links = []
for u in ulist:
    for v in vlist:
        base = surf.value(u, v)
        normal = surf.normal(u,v)
        rot = App.Rotation(App.Vector(0,0,1), normal)
        box = Part.makeBox(boxLength, boxLength, boxLength)
        centerpl = App.Placement(-(boxLength/2) * App.Vector(1,1,1), App.Rotation())
        box.Placement = App.Placement(base, rot) * centerpl
        boxdoc = Part.show(box, 'Box')
        links.append(boxdoc)

cmpd.Links = links
doc.recompute()

keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Curves workbench

Post by keithsloan52 »

edwilliams16 wrote: Sun Dec 04, 2022 9:01 am @keithsloan52

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("IsoCurve")
ob, fa = obj.Face
face = getattr(ob.Shape, fa[0])
surf = face.Surface
umin, umax, vmin, vmax = sub.ParameterRange
nu = obj.NumberU
ulist = [i*(umax - umin)/nu + umin for i in range(nu+1)]
nv = obj.NumberV
vlist = [i*(vmax - vmin)/nv + vmin for i in range(nv+1)]
boxLength = 2
cmpd = doc.addObject("Part::Compound","CompoundBoxes")
links = []
for u in ulist:
    for v in vlist:
        base = surf.value(u, v)
        normal = surf.normal(u,v)
        rot = App.Rotation(App.Vector(0,0,1), normal)
        box = Part.makeBox(boxLength, boxLength, boxLength)
        centerpl = App.Placement(-(boxLength/2) * App.Vector(1,1,1), App.Rotation())
        box.Placement = App.Placement(base, rot) * centerpl
        boxdoc = Part.show(box, 'Box')
        links.append(boxdoc)

cmpd.Links = links
doc.recompute()

Thanks for the suggestion.

Where is sub being set?

Also look alike don't meet the spec, what needs to be created is an Array of the GDMLObject being passed. In the test case a GDMLBox.
The first item should be a GDMLObject the rest have to be links back to the first but with different position, rotation.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

My mistake sub = face
I missed the substitution and didn’t test. I assume you can turn Part boxes into gdml boxes.
The only addition to code I had already posted was

Code: Select all

Surf =face.Surface
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Curves workbench

Post by keithsloan52 »

edwilliams16 wrote: Sun Dec 04, 2022 1:12 pm My mistake sub = face
I missed the substitution and didn’t test. I assume you can turn Part boxes into gdml boxes.
The only addition to code I had already posted was

Code: Select all

Surf =face.Surface
Already had
surf = face.Surface
It was the sub in the following?
umin, umax, vnin, vmax =sub.ParameterRange
So should it be ?
min, umax, vmin, vmax = surf.ParameterRange

I just tried and it appears not
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

Code: Select all

umin, umax, vmin, vmax = face.ParameterRange
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Curves workbench

Post by keithsloan52 »

Well it runs BUT

Objects are NOT at the intersection of IsoLines
Orientations are not correct.

Least when I used the edges in the IsoCurve, I managed to get the locations correct.
3DD4CC9A-66E4-4687-A0F2-E11B0A687B4D.jpeg
3DD4CC9A-66E4-4687-A0F2-E11B0A687B4D.jpeg (115.86 KiB) Viewed 1087 times
Test-ISO-C.FCMacro
(2.62 KiB) Downloaded 12 times
IsoCurve_Test_After_Macro.FCStd
(195.27 KiB) Downloaded 12 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

@keithsloan52
I shouldn't make code changes without a computer in front of me... Made an off-by-one error.

However, the orientation issue didn't show in the test case - only when I change the number of contours. I oriented them along the latitude lines.
It isn't clear which orientation the cube on the top should have, so I've omitted it at present.

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("IsoCurve")
ob, fa = obj.Face
face = getattr(ob.Shape, fa[0])
surf = face.Surface
umin, umax, vmin, vmax = face.ParameterRange
nu = obj.NumberU - 1
ulist = [i*(umax - umin)/nu + umin for i in range(nu + 1)]
nv = obj.NumberV - 1
vlist = [i*(vmax - vmin)/nv + vmin for i in range(nv + 1)]
boxLength = 2
cmpd = doc.addObject("Part::Compound","CompoundBoxes")
links = []
for u in ulist:
    for v in vlist[1:]:
        base = surf.value(u, v)
        normal = surf.normal(u,v)
        #rot = App.Rotation(App.Vector(0,0,1), normal)
        tangents = surf.tangent(u, v)
        print(f'{tangents[0]} {normal}')
        rot = App.Rotation(tangents[0], App.Vector(), normal, 'ZXY')
        box = Part.makeBox(boxLength, boxLength, boxLength)
        centerpl = App.Placement(-(boxLength/2) * App.Vector(1,1,1), App.Rotation())
        box.Placement = App.Placement(base, rot) * centerpl
        boxdoc = Part.show(box, 'Box')
        links.append(boxdoc)

cmpd.Links = links
doc.recompute()


Screen Shot 2022-12-04 at 9.06.15 AM.png
Screen Shot 2022-12-04 at 9.06.15 AM.png (31.72 KiB) Viewed 1059 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

@Chris_G

The NumberU is misleading here. The number of curves is NumberU -1 - ie 5
Screen Shot 2022-12-04 at 9.41.25 AM.png
Screen Shot 2022-12-04 at 9.41.25 AM.png (33.12 KiB) Viewed 1040 times
Screen Shot 2022-12-04 at 9.41.49 AM.png
Screen Shot 2022-12-04 at 9.41.49 AM.png (24.59 KiB) Viewed 1040 times
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Curves workbench

Post by Chris_G »

edwilliams16 wrote: Sun Dec 04, 2022 7:43 pm The NumberU is misleading here. The number of curves is NumberU -1 - ie 5
Probably because the surface is closed in that direction, so the seam edge is doubled.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

You are right. I exploded the compound, and the seam edge is doubled.
Post Reply