Hi all, Q1: How do I in simplest thinkable manner compare the direction of a curve and a nearby surface using PythonScript? Q2: And how to swap directions for Surfaces?
For curves I can use rs.ClosedCurveOrientation(), but if I want to compare the directions of a curve with the orientation of a nearby surface it seems to be trickier. I actually couldn’t find out by even searching the Python script library for how examples of tricking with the directions of surfaces.
I guess I could extract Isocurves, or an edge, from the surface and then compare with that curve, but that seem like a far fetched solution, and that still doesn’t tell me how to swap the directions of the surface, if need be.
I tried searching the entire Python script directory for the words orientation & direction but could find anything meaningful (for surfaces). Probably because I don’t know what terms to search for at the script level.
I need to script-swap directions also for surfaces, not only for curves (rs.ReverseCurve(curve))
@AIW: UVN is what I need if I’m to switch directions (relative to the another nearby curve or surface).
@djordje: Ops! How could I miss that one? Thanks for pointing me to the right place.
But now, how do I determine the UV directions of a surface?
I found from the same page that rs.SurfaceClosestPoint() returns a point value, so comparing two points on the same surface should be useful for determining the UV directions of a surface, or is there any other better approach?
[edit: fixed a missing “-1” in the upper right corner)
I’m not capable of reading out from the numbers whether the UV directions are swapped or not (similar numbers for Flipped (only) as for Swapped + Flipped), how then can I swap them correctly (given that I know how I want them in each case).
The first four cases (FLIP row) makes sense to me, but not the last four cases (they are identical to the first four). < scratching head >
I think your suggestion covers my Q1, in that I from your code example can determine the “flip” directions.
But if I also want to swap a surface (aligning the UV directions for two adjacent surfaces) then I can’t derive from the numbers how the surfaces’ UV’s are swapped. That was not explicitly stated (sorry) but I think it’s a (perhaps too farfetched) implication of “swap” in Q2.
Edit: If the wisdom is that it doesn’t really matter (anywhere) which way the “red” and the “green” are swapped, then so be it, I’m content with that. But if it has any significance, which I am ignorant of as a newbie, then my Q2 makes sense. But if you can clarify that I can disregar4d the “swapping” direction, then I can get where I want with your code.
When you say “flip”, you mean you reverse the U and/or V direction of a surface? Because in Rhino, “flipping of surface” is associated with reversing of surface normal (vector) direction.
And yes, swapping the U and V direction affects the surface significantly. Try for example evaluating a point on a surface with a certain u,v parameters. Swap the U and V directions, and try that again. You will see how swapping affected the surface.
But I still do not understand your upper photo and what you are trying to do.
You are reversing the U and V directions, and swapping them. What for? And which part of this reversing and swapping of U and V directions is not working correctly?
Edit: No, I am NOT reversing or swapping. I am trying to find out the directions (in the test case illustrated), and then, if I can do that (all 8 cases), then I know what to flip or swap (no problem with that part).
I want to be able to determine all the illustrated directions so I can align the UVNs of two adjacent surfaces. I have use for that i different scripts.
So therefore I am trying to figure out if I can derive all the eight (8) cases illustrated.
But these numbers don’t seem to disclose all the info needed to determine that (the swapping, that is).
If I’m able to determine if they are Swapped, then I’m also able to Swap and Flip any surface to whatever directions I want.
I managed to derive if Reversed, but not if Swapped (either relative to World or another object).
Try for example evaluating a point on a surface with a certain u,v parameters. Swap the U and V directions, and try that again. You will see how swapping affected the surface.
Forget about the word “flipping”. I understand that you associate “flip” ONLY with surfaces (the “normal”), but the term “Flip” is also used in the DIR command to reverse curves (so therefore I carelessly used the term “flip” also for surfaces in my posts, but never mind, the picture illustrates nothing about surface normals, it only illustrates the UV directions, so please bare with me, we talk about reverse and swap only.).
So, forget about the term “flip” and reread my posts as saying “reversed” instead of “flip”.
With my eyes I can see the difference (but I avoid using words here to describe the difference as to not confuse anyone by perhaps using the wrong terms). I say only “the first four are not the same as the last four” and therefore I repeat my question:
How can I know the difference between the upper four Reversed surfaces and the lower four Swapped surfaces by examining the UV data? (the UV numbers are obviously the same for reversed as for swapped [edit+] so these numbers don’t tell the whole story, I presume).
The photos do not correspond to the blue numerical values above each photo.
How did you get those blue numerical values?
@djordje, I ran the code which you provided on the pictured surfaces. What about the numbers is not correct?
Can you elaborate on the practical geometric situation you are dealing with. I feel this discussion is abstract, yet you are solving a concrete situation.
@Willem, Regarding the concrete situation, I’d be satisfied with the info I already got about the “UVReverse” of surfaces (I’d compare with other adjacent surfaces, disregarding the “swap-direction” since matching “reverse-directions” seems to suffice, no?).
But, then djordje said that if I put a point on the surface, and then swap the surface, then I wouldn’t get the same result. Well, I tried that, and I got similar results for a point on the surface as for the surfaces themself (as illustrated).
But it still seems strange that one cannot determine which way the “red” vectors are directed.
I did not take the blue tekst in consideration. Sorry for the confusion. As Im on my phone it’s rather difficult to elaborate on my thoughts on this.
It’s still not clear what your practical situation is.
How are the 2 surfaces positioned when you want to align their UV’s? Are the in parallel or randomly positioned. Are the UV directions matching and is all you need figuring out what goes where?
If the latter, you’d need to test what directions match up. And next find if the matches are in the same direction. That will determine if you need a swap reverse or both. It’s a puzzle to get the correct setup to do this but that is my take on it without actually testing.
Also take the normals in account, if the normals are not in the same direction, the u and v direction can never align (if I’m not mistaken )
See the right hand rule for xyz coordinate system.