Finding Direction / Orientation for Curves & Surfaces

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. :frowning:

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))

// Rolf

What are you using to define the direction of a surface?

Hi Rolf,

The rs.ReverseSurface function enables reversing its u and v directions and swapping them as well.

@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?

// Rolf

Hi Rolf,

You can probably do it like so.

You can also find the frame (plane) at certain point on a surface. Those plane’s X and Y axes represent surface U and V direction vectors:

import rhinoscriptsyntax as rs

srfId = rs.GetObject("pick a surface", 8)
ptId = rs.GetPointOnSurface(srfId, "pick a point on the surface")
uv = rs.SurfaceClosestPoint(srfId, ptId)
plane = rs.SurfaceFrame(srfId, uv)
UdirectionVector = plane.XAxis
VdirectionVector = plane.YAxis

… And for curves

rs.CurveTangent()

Hi @djorgje,

I struggle to understand how to determine both direction and axis from the results of this (your) code:

uv = rs.SurfaceClosestPoint(srfID, pointID)
plane = rs.SurfaceFrame(srfID, uv)
print "U :", plane.XAxis
print "V :", plane.YAxis

I get the following results for these eight cases (4x Flip & 4x Swap+Flip:

[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 >

// Rolf

Hi Rolf,

Your penultimate question was:

Upper posted penultimate reply does that.

I am not sure I understand your last reply in response to it.

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.

// Rolf

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?

Yes, then we are on the same page there.

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).

// Rolf

It doesn’t look that way. On upper four surface examples from your photo, you are reversing the U and V directions of the surface. You are not flipping the surface normal.

Didn’t you derive them already? What is wrong with upper 8 combinations from the photo?

I didn’t understand you this part.

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”.

Yes, this is why I said:

I do not understand your issue, sorry.

I updated the picture replacing the word “FLIP” with “REVERSE”.

Now, again, how do I determine the difference between the first four upper surfaces in the picture, and the last four surfaces by examining the numbers? The picture again, for your convenience:

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).

// Rolf

From the perspective of the surfaces they are equal sets. For example: top left equals bottom right.

EDIT: to make matters worse, there are just 2 different planes here:
Top 1,3 Bottom 2,4 are facing us
Top 2,4 Bottom 1,3 are facing away

Yet from an external standpoint they are rotated around the z axis as well.

So you need an external frame of reference.

If you have the tangent of a curve, you can compare it against the U and V direction and find the one most parallel and then test if the directions match.

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

The U and V direction vectors in 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?

@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.

// Rolf

@Willem, How can I determine that from the numbers?

(I can’t see even with my eyes that is so… Can you explain how you arrive at it being so?)

// Rolf

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.

http://www.google.com/search?q=right+hand+rule+xyz

-Willem