Jump to content

Is there a way to get the UV position of a point on a curve?


magneto

Recommended Posts

Hi,

This is the opposite of what I asked last time. Basically I have 2 curves that are totally different by their length and number of points.

What I am trying to do is to get the normalized UV coordinate of a point on Curve A, say point 3 is 0.271, and then get the corresponding point position in Curve B. In this case I would use primuv and feed it the UV coordinate I have which is 0.271.

But I don't know how to get these normalized UV values for each point.

I looked at the UV Texture SOP and used the Arclen Spline Length and other spline options and then normalized these values to 0-1, but the coordinates do not match, when I used Curve A for primuv.

Can I calculate these UV values by measuring the length up to each point, dividing the result by the total curve length? I am not sure how to measure up to a point though since the arclen function requires UV coordinates.

Anyhow is there a way to do this?

Thanks :)

Link to comment
Share on other sites

But I don't know how to get these normalized UV values for each point.

{ WoW ! nonCommercial version doesnt let me Paste code .. Haa ! another handjob for me }

fit( $MAPU, 0, point( `opinputpath( '.',0 )`, $NPT-1, "uv", 0 ), 0, 1 )

--

here is a file which seems to work

- with or without UVs ( Measure SOP assigns distance as attrib to each point ) ..

- NURB / polys ..

--

getProportionalLocation.hipnc

--

.cheers

  • Like 1
Link to comment
Share on other sites

Thanks zarti. You can copy using the NC version. Just open the external editor (Alt+E) :)

So I looked at your file and found that you used the expression you posted in attribcreate1, which is connected to curve1. That was exactly what I was doing, but in this nodes until attribcreate1 there is no Measure SOP. I noticed you use it in other parts of the file.

But the values calculated using my_distance doesn't give the correct values :)

Try this expression:

primuv("../attribcreate1", 0, "P", 0, point("../attribcreate1", 6, "my_distance", 0), 0)

and you will see that returned value will not be the same as Point 6's X value.

As for the Measure SOP, I noticed you were using Blast SOPs. Were you trying to delete everything but 1 segment and then measure its length? Because if you measure after deleting, the length of the segment changes.

Thanks again :)

Edited by magneto
Link to comment
Share on other sites

You can copy using the NC version. Just open the external editor (Alt+E) :)

oh thanks , ill try to remember that .

--

Measure SOP , which i mentioned in the first reply , was not part of the NURB's case . it was in the branch of polygon case and have used it before to measure segment lengths ( while in this one to measure ' how far ' is each point from point 0 ) . so , i could find the ratio to feed into Carve SOP or primuv expression ... but ,

But the values calculated using my_distance doesn't give the correct values :)

Try this expression:

primuv("../attribcreate1", 0, "P", 0, point("../attribcreate1", 6, "my_distance", 0), 0)

and you will see that returned value will not be the same as Point 6's X value.

.. but it should give exact values if segments are equal ( points distributed uniformly ) .

so Carve and primuv exp. obey to something else but not 'physical lengths' .

sad . and dont know Why that ( ??! )

edit: i tried to use a curve with all segments equal to each other and my method works .

--

As for the Measure SOP, I noticed you were using Blast SOPs. Were you trying to delete everything but 1 segment and then measure its length? Because if you measure after deleting, the length of the segment changes.

that Blast-ard escaped the cleanup i made of some nodes i was testing inside foreach . it is useless actually .

--

so maybe a solution wd be to evenly resample curves ( in a parallel branch maybe ) to get the most accurate result possible without affecting original ones .

Edited by zarti
  • Like 1
Link to comment
Share on other sites

Thanks a lot guys.

@John: I looked at your file, cool techniques but when I tried to feed the Red color values to primuv expression's u argument, it's still not exact to actual point positions. Were you able to see identical results on your tests?

@zarti: I see what you mean. Uniform works for sure. But if the points are uniform, $PT/($NPT-1) would work too because the u coordinates would also be uniform.

Are you sure Carve and primuv doesn't use the physical length? Since I don't know the exact U values of points, I can't verify 100%, but my tests show the U values you use for Carve and primuv seem to be precise by length.

I think that's why finding the U coordinate is tricky :)

  • Like 1
Link to comment
Share on other sites

her is the proof Carve ignores physical length of curves ( primuv() should be the same ):

- the segments are equal ( build with snapping to grid ON )

- set to display the nodes in black .

the Carve is animated with linear() interpolation , while as you can see the speed is affected by points density .

--

getProportionalLocation_proofOfNonLinearity.hipnc

--

edit : if you create an UVTexture with texture type = Average Spline , it works here .

put this in attributecreate2 node :

$MAPU / point( opinputpath('.',0), $NPT-1, "uv", 0 )

but im guessing you already have UVs .. or not ??

edit2 : attachment added ..

--

getProportionalLocation_workingWithAverageSpline.hipnc

--

Edited by zarti
Link to comment
Share on other sites

Thanks zarti. Your idea works when the curve order is 2, when I increase it to 4, the values shift again :)

I am not sure if Carve and primuv is supposed to be linear. Perhaps someone can shed a light? I have another idea to try so if it works, I will post it here. If it doesn't work, I will post it here :)

Link to comment
Share on other sites

@John: I looked at your file, cool techniques but when I tried to feed the Red color values to primuv expression's u argument, it's still not exact to actual point positions. Were you able to see identical results on your tests?

Attached file includes how I was planning to fetch point position based on normalized U value. I don't have any experience with the primuv expression, but in the file providing a U value between 0-1 returns an exact point position on the input curve. As far as the U coordinates being assigned to the curve, those are still an approximation.

Assign_U_Coordinates_to_a_Curve_ToPublic_v002.hip

  • Like 1
Link to comment
Share on other sites

Thanks John, very useful. I looked at the file again. How do you compare your generated U values to return the matching XYZ coordinates? Like which expression are you using?

In the v002 file I just uploaded there's some added sops colored in like a mustard yellow. Using a point sop I'm shuffling P into Cd and $CR into $TX. $TY and $TZ are zeroed out. This creates a normalized line in the positive X direction.

With the add sop I'm creating 1 point with a slider range 0-1 this slider sets $TX for the newly created point. Using a vopsop and pcfilter the nearest point's color is retrieved (which is actually the position).

Kinda confusing, probably could be simplified, but it's what I came up with.

  • Like 1
Link to comment
Share on other sites

Thanks guys.

@John: I will have to inspect your file more closely. I couldn't find time yesterday :)

@petz: $PT / ($NPT - 1) only works for uniform points on a curve. If they are all over the values do not work.

I looked at unituv from the docs but not sure how it works? I checked your file but the U values seem to be the same as $PT / ($NPT - 1).

Link to comment
Share on other sites

Hi, If you're working with polys, then you should convert your curves to nurbs, order 2.

Use a basis SOP and change U parameterization to 'Approximate Arc Length'.

The carve SOP and primuv etc. will use the new parameterization.

EDIT: should probably add that changing the parameterization of nurbs with order > 2 will change the shape of your curve a little.

Thanks guys.

@John: I will have to inspect your file more closely. I couldn't find time yesterday :)

@petz: $PT / ($NPT - 1) only works for uniform points on a curve. If they are all over the values do not work.

I looked at unituv from the docs but not sure how it works? I checked your file but the U values seem to be the same as $PT / ($NPT - 1).

Edited by stabby
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...