UV Space Orientation

Need help, or want to share a macro? Post here!
Post Reply
thyssentishman
Posts: 49
Joined: Mon May 16, 2022 10:35 am

UV Space Orientation

Post by thyssentishman »

Hi all,

I've been trying to write a script that creates a path of points along the center of curved surfaces and stores it coordinates and normal values. I do this by using the uv-space ranges. This is what I've done so far:

- First I select a face of a body and get its uv-space parameter ranges
- Then I choose the parameter range I want to keep constant (e.g. u)
- I find its middle value ((umin + umax) / 2)
- Then I loop through the range of v parameters, incrementing it with a defined step (e.g. range(vmin, vmax, step))
- I save each points coordinates and normal vector in an list and export it as a csv file

This works well, however I want to be able to do this with multiple adjacent faces at once. The problem here is that the orientation of the uv-space is not always the same. For example, if I have two adjacent rectangular faces, the width of the first rectangle might be represented with the u range and the width of the second rectangle with the v range. That means that if I select the u range to be constant, I will get a longitudinal path for the first rectangle and a transversal path for the second (see attachment). I want both to be longitudinal or transversal.

I've been trying to find a way to harmonize the orientation of these paths when done with multiple faces, but so far I haven't been successful.

I kindly want to ask the experts for some help. Is there a way to determine the orientation of the uv-space or to rotate it? Is there maybe a better approach to this?

I hope I was clear enough. Please let me know if more information is required.
Attachments
bitmap.png
bitmap.png (9.97 KiB) Viewed 413 times
User avatar
Chris_G
Veteran
Posts: 2129
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: UV Space Orientation

Post by Chris_G »

I would need more context about your ultimate goal.
In general, you have absolutely no control over the UV space (= the geometric surface) of a face (unless you are building the face yourself).
Since you seem to desire a continuous path over multiple faces, you can't rely only over their surfaces.
You need to choose a method to get your sampling path.
For example, by creating multiple slices of your shape :

Code: Select all

aShape.slices(FreeCAD.Vector(0,0,1), [0.0, 0.2, 0.4, 0.6])
It returns a compound of wires
So you can discretize each wire, or each edge of the wire individually :

Code: Select all

aWire.discretize(Number=100)
And use these points to get a normal value on the shape.
thyssentishman
Posts: 49
Joined: Mon May 16, 2022 10:35 am

Re: UV Space Orientation

Post by thyssentishman »

Hi Chris,

thanks for your quick reply. Basically I want an user to be able to select a set of adjacent faces on an object and through a script generate a path of points on the longitudinal center of the overall face (all faces combined). Please see the attachment for an example of what I mean. I want to automate as much as possible which is why I only want the user to select the faces and run the script.

About the method you suggested, how can I get the slices to be displayed on the tree? I ran your code and it seems to succeed, but I see nothing in the tree. Also, and please correct me if I'm wrong, the method you suggest would take a Shape as input right? Meaning that I would get slices of the whole body and not only the selected objects, correct? I assume this is why you suggest to discretize only the wire of a slice at a given position. The thing is that for certain object I might only want the path to be generated for the selected faces and not for the whole body.
Attachments
select_faces.png
select_faces.png (34.39 KiB) Viewed 372 times
result.png
result.png (31.05 KiB) Viewed 372 times
User avatar
Chris_G
Veteran
Posts: 2129
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: UV Space Orientation

Post by Chris_G »

rvq wrote: Mon May 16, 2022 1:35 pm generate a path of points on the longitudinal center of the overall face (all faces combined)
So the question is : How do you define "longitudinal center" ?
In the most general case, a group of connected faces doesn't have such a "longitudinal center".
Unless these faces have some more properties, like a common height, as in your example ...
rvq wrote: Mon May 16, 2022 1:35 pm About the method you suggested, how can I get the slices to be displayed on the tree?

Code: Select all

theSlices = aShape.slices(FreeCAD.Vector(0,0,1), [0.0, 0.2, 0.4, 0.6])
SliceObject = Part.show(theSlices, "Slices")
rvq wrote: Mon May 16, 2022 1:35 pm The thing is that for certain object I might only want the path to be generated for the selected faces and not for the whole body.
Then you build your own shape with the selected faces :

Code: Select all

myShape = Part.Compound(selectedFaces)
Or, if all the faces are connected, you can specifically build a shell :

Code: Select all

myShape = Part.Shell(selectedFaces)
But it may not succeed all the time ...
thyssentishman
Posts: 49
Joined: Mon May 16, 2022 10:35 am

Re: UV Space Orientation

Post by thyssentishman »

Chris_G wrote: Mon May 16, 2022 2:21 pm In the most general case, a group of connected faces doesn't have such a "longitudinal center".
What about an average? Can something like this be done? Because you are right, the bodies I want this script to work with mainly don't have a constant width and have organic-like shapes.
Chris_G wrote: Mon May 16, 2022 2:21 pm Then you build your own shape with the selected faces :
Ok, so here is what I did for a selected set of adjacent faces:

Code: Select all

mySelection = FreeCADGui.Selection.getSelectionEx()[0].SubObjects
myFace = Part.Compound(mySelection)
mySlices = myFace.slices(FreeCAD.Vector(0,0,1), [0.0, 0.2, 0.4, 0.6])
SliceObject = Part.show(mySlices, "Slices")
However I get the following error:

Code: Select all

<Part> ViewProviderExt.cpp(2159): Cannot compute Inventor representation for the shape of Unnamed1#Slices
EDIT: I tried this same code with the example body that can be seen in the attachment and it works as expected. However I believe that what I explain below still remains true.

Also from what I can deduce from the slices command, the first argument indicates the direction on which the slice will be made correct? In other words, the axis to which the slice will be orthogonal? If this is the case, then this method will simply not work for my case, since like I said before, the bodies I'm working with have organic-like shapes and and their faces are almost never orthogonal or parallel to a plane/axis.

Is there maybe a way to slice a body across its own curvature? Please see attachment to see what I mean.
Attachments
cross_section.png
cross_section.png (47.25 KiB) Viewed 308 times
Post Reply