How to create isocurves on faces?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
How to create isocurves on faces?
I'm trying to explain some basics about UV surfaces, so I have made some example code to show isogrids, but it don't work as expected.
https://forum.freecadweb.org/viewtopic. ... 6&start=10
Probably there is some stupid error (and probably is about some basic things about Topology).
Here the code:
Edit:
Found stupid errors, now problem is how to limit the upper and lower face of the cylinder to the real "face area"?
End >Edit
Anyone could be of any help:
Regards
Carlo D.
https://forum.freecadweb.org/viewtopic. ... 6&start=10
Probably there is some stupid error (and probably is about some basic things about Topology).
Here the code:
Edit:
Found stupid errors, now problem is how to limit the upper and lower face of the cylinder to the real "face area"?
End >Edit
Anyone could be of any help:
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: How to create isocurves on faces?
I think this can work:
Code: Select all
face.common(edge)
Re: How to create isocurves on faces?
Thanks, I will try, as usual answer is not too far (if you know in what direction to go!)
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: How to create isocurves on faces?
This code seems to work for sphere, cylinder, cone, box and torus probably it is rough as parameters are derived in a rough way.
Thanks @Roy_043
Edit:
Added a different parametrization for u and v divisions.
End edit:
Regards
Carlo D.
Thanks @Roy_043
Edit:
Added a different parametrization for u and v divisions.
End edit:
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Veteran
- Posts: 3112
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: How to create isocurves on faces?
@onekk
It even works for a complicated B-spline surface, which the Curve WB|Surfaces|IsoCurves tool fails on.
I changed the list isocurves to isocurveslist because it was shadowing the function of the same name.
For @Chris_G
It even works for a complicated B-spline surface, which the Curve WB|Surfaces|IsoCurves tool fails on.
Code: Select all
shp = App.ActiveDocument.getObject("Sweep").Shape
isocurveslist = isocurves(t_shp, divs, False, True)
for f_idx, iso_c in enumerate(isocurveslist):
Part.show(iso_c, f"face_{f_idx}_ic")
For @Chris_G
Code: Select all
12:42:34 Traceback (most recent call last):
File "/Users/ed/Library/Application Support/FreeCAD/Mod/Curves/./freecad/Curves/IsoCurve.py", line 108, in execute
w = isocurves.multiIso(face, selfobj.NumberU, selfobj.NumberV).toShape()
File "/Users/ed/Library/Application Support/FreeCAD/Mod/Curves/./freecad/Curves/isocurves.py", line 156, in toShape
c.append(u.toShape())
File "/Users/ed/Library/Application Support/FreeCAD/Mod/Curves/./freecad/Curves/isocurves.py", line 89, in toShape
bounds = self.faceBounds2d()
File "/Users/ed/Library/Application Support/FreeCAD/Mod/Curves/./freecad/Curves/isocurves.py", line 71, in faceBounds2d
if _utils.geom_equal(pc[1], self.face.Surface):
File "/Users/ed/Library/Application Support/FreeCAD/Mod/Curves/./freecad/Curves/_utils.py", line 363, in geom_equal
if not have_equal_property(geom1, geom2, prop, tol):
File "/Users/ed/Library/Application Support/FreeCAD/Mod/Curves/./freecad/Curves/_utils.py", line 310, in have_equal_property
attr1 = getattr(geom1, prop)
<class 'Base.FreeCADError'>: Unknown exception while reading attribute 'UKnotSequence' of object 'GeomBSplineSurface'
12:42:34 Recompute failed! Please check report view.
- Attachments
-
- isocurvesbsplinesurface.FCStd
- (62.48 KiB) Downloaded 14 times
Re: How to create isocurves on faces?
Thanks for participating, my fault for the choice if names sometimes you are catched in coding and don't see such genre of things.edwilliams16 wrote: ↑Thu Jul 07, 2022 10:48 pm @onekk
It even works for a complicated B-spline surface, which the Curve WB|Surfaces|IsoCurves tool fails on.
...
I changed the list isocurves to isocurveslist because it was shadowing the function of the same name.
Now I have to formalize in a decent way these findings to make a decent explanation.
Speaking of code the "common" will select correctly only the part of the U,V surface covered by the face as example for cylinder's upper and lower faces.
There is a way to find boundaries of the face in the UV Surface?
There is a way to chech if a UV coordinate is on the face or outside the face?
Regards.
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: How to create isocurves on faces?
Thanks. This is fixed.
Not directly.
You have to loop over the face OuterWire edges, and extract the pcurves :
Code: Select all
for e in face.OuterWire.Edges:
curve2d, fp, lp = face.curveOnSurface(e)
Code: Select all
face.isPartOfDomain(u, v)
Re: How to create isocurves on faces?
Chris_G wrote: ↑Fri Jul 08, 2022 9:33 amNot directly.
You have to loop over the face OuterWire edges, and extract the pcurves :Code: Select all
for e in face.OuterWire.Edges: curve2d, fp, lp = face.curveOnSurface(e)
Thanks for answering.
I have put together this test code for a cylinder:
Code: Select all
for f_idx, face in enumerate(t_shp.Faces):
print(f"face_{f_idx} >> {face}")
for e in face.OuterWire.Edges:
curve2d, fp, lp = face.curveOnSurface(e)
print(f"curve {curve2d}, fp: {fp} lp: {lp}")
Code: Select all
face_0 >> <Face object at 0x556837fa9d50>
curve <Line2d object>, fp: 0.0 lp: 6.283185307179586
curve <Line2d object>, fp: 0.0 lp: 20.0
curve <Line2d object>, fp: 0.0 lp: 6.283185307179586
face_1 >> <Face object at 0x55683a258080>
curve <Circle2d object>, fp: 0.0 lp: 6.283185307179586
face_2 >> <Face object at 0x55683a258320>
curve <Circle2d object>, fp: 0.0 lp: 6.283185307179586
A little explanations, about face_0, I could guess that is returned as a "square", but it seems that there is a missing line to close the square?
Probably I'm guessing wrong.
TIA and Regards.
Carlo D.
Last edited by onekk on Fri Jul 08, 2022 7:36 pm, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: How to create isocurves on faces?
Unfortunately, yes. Not very funny.
Or it may be less work to do a boolean operation in the XY plane.
This allows you to work with all the features offered by topology (like boolean operations).
- create a flat representation of the face outerwire on XY plane :
Code: Select all
flat_edges = []
for e in face.OuterWire.OrderedEdges:
curve2d, fp, lp = face.curveOnSurface(e)
flat_edges.append(curve2d.toShape(fp, lp))
Code: Select all
face = Part.Face(Part.Wire(flat_edges))
Code: Select all
import numpy
vec2 = FreeCAD.Base.Vector2d
u0, u1, v0, v1 = face.ParameterRange
uiso = []
for u in numpy.linspace(u0, u1, nb_samples):
uiso.append(Part.Geom2d.Line2dSegment(vec2(u, v0), vec2(u, v1)).toShape())
# do the same for viso
grid = Part.Compound(uiso + viso)
- loop through the trimmed grid edges, and map them back on the original face.
One of the edges of the outerwire is a seam edge.
You can test with :
Code: Select all
edge.isSeam()
Currently, it is not possible to obtain the second pcurve with face.curveOnSurface(edge)
The easiest way is to loop over the wire OrderedEdges like I did above, where the seam edges are repeated.
Re: How to create isocurves on faces?
Many thanks for the insight.
I have many things to study as usual.
Tanks again and best regards.
Carlo D.
I have many things to study as usual.
Tanks again and best regards.
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/