*On 17/06/2005 at 07:24, xxxxxxxx wrote:*

User Information:

Cinema 4D Version: 9.1

Platform: Windows ;

Language(s) : C++ ;

---------

Hi,

I have a point on a polygon and would like to retrieve the uvw coords for this point. I can get the uvw data from the uvw tag for the polygon, but how do I retrieve the exact uvw coordinate for the point? If I had barrycentric coords I could calc it from those but I haven´t :)

Any help appreciated

Katachi

*On 18/06/2005 at 08:39, xxxxxxxx wrote:*

Thanks Dave, I have a look. :)

]]>*On 18/06/2005 at 04:52, xxxxxxxx wrote:*

There are faster ways to calc the barys than the areas, just do a google for them and you'll find lots of info :) flipcode is generally a good source.

As for n-gons (I noticed them mentioned), you never really need to worry about them since they will always have quads/tris, its rare (only modeling generally) where you need to consider n-gons in CINEMA. UVs are done on the polygon mesh, not the n-gons.

If you do go with the barys then since you can use them to find if a point is in a tri just calc for one tri, if its in range you have it, if not do the other. Its pretty simple and fast.

*On 18/06/2005 at 01:14, xxxxxxxx wrote:*

yep, thanks. I first have to get the area calculation. I have an old formula for this I remember, let´s see if it works. :)

]]>*On 18/06/2005 at 01:08, xxxxxxxx wrote:*

Not that it's not enough, but that it's a limited solution (only triangles). ;P

Note that you still need interpolation after the simple barycentric coordinate determination. Oh, the joys of nonlinear interpolation... :)

]]>*On 18/06/2005 at 00:20, xxxxxxxx wrote:*

thanks, I wanted to go with Barys from the beginning but someone said it wasn´t enough ;)

Thanks for the info about the bary calculations though!

*On 18/06/2005 at 00:06, xxxxxxxx wrote:*

Well, here's the response that I received. If more information is needed, at least a search of 'barycentric' and 'bilinear' may provide more information.

_I have a solution for triangles, that may be enough for you. The true answer for n-sided polygons depends on the method your renderer is using to interpolate the UV coordinates. For triangles, barycentric is the most common, and for quadrangles, bilinear is common.

Anyhow, here's what I did when I needed to do this for triangles. I'd either assume that P is in the plane defined by the triangle, or project it to that plane. Then I'd have the vertices of the triangle ABC, with P in the triangle. I'd compute the area of the 3 triangles ABP BCP and CAP. Then the barycentric coordinates of the points A B and C are the areas of the opposite triangles, divided by the sum of the areas. In other words, bary(A) = Area(BCP)/(SumOfAreas). Then use barycentric interpolation of the UVs to find the correct interpolated UV coordinate of P._

And I agree with David that if you want to use a simple triangular method, best to subdivide n-gons into triangles (very easy) and go from there with Barycentric interpolation.

]]>*On 17/06/2005 at 23:42, xxxxxxxx wrote:*

Hi,

thanks, but where do I get the bary coords from? I am in a generator so VolumeData I cannot use (I would have used GetRS or GetWeights then).

Thank you!

]]>*On 17/06/2005 at 12:49, xxxxxxxx wrote:*

Just calculate the coordinates yourself, there are a number of ways. If its a tri, then its simply the bary coords, if its a quad then a simple one is to split the quad into two tris and use the one the point is in with the barys again. You can get better ones that give a better interpolation over the quad, is volumedata available to you? if so look at the GetRS function and it'll do it all for you.

]]>*On 17/06/2005 at 12:25, xxxxxxxx wrote:*

But how much distortion (including the simple flip, mirror, skew, rotation) will you be able to tolerate? Every human mesh that I've dealt with had extremely high polygon distortion. This is why it's nonlinear. Calculus is necessary to do the interpolation under these circumstances.

I'm doing a search of ACM and have asked in a related forum, but have yet to pinpoint the actual math/algorithm involved. This is more mathematical than graphics based - most of the references go directly to mapping the texel to screen space.

]]>*On 17/06/2005 at 11:10, xxxxxxxx wrote:*

That doesn´t matter to me. I expect the user to have a mesh with clean UV data (and my experience tells me that this is most of the time the case if we exclude beginners).

One has to choose whether it´s worth exchanging performance with correctness and completeness (or vice-versa). And in my case speed is the only issue I am concerned about, so complex calculations are inacceptable to me.

Anyway, for my task it wouldn´t even matter if all points have the same uv coordinate. The user has to take care of it when he wants to use UV data. (which should usually of course be handled by the plugin)

]]>*On 17/06/2005 at 10:57, xxxxxxxx wrote:*

But the UVW coords of the polygon vertices (where not procedurally mapped) can be user edited. There is no transformation correlation between them. In other words, the UVW points can be in virtually any configuration; they are point-point mapped (all of the UV points could have the same UV coordinate, be on a line, or worse). You can easily get points along the edges because you have the two end points. But the space enclosed by a set of UV points is in no way directly correlated to the space enclosed by the XYZ points. This is nonlinear space transformation. This requires partial-derivations. Expect to see lots of 'dU/dV' while looking for a solution.

]]>*On 17/06/2005 at 10:46, xxxxxxxx wrote:*

It cannot be too complex (sure, more complex than just retrieving the UVW coord) as there are plugins out there retrieving them pretty fast (I just don´t know how they do it :). Barrycentric coords would definetly help as I could use them as weights for the uv coords of the poly points.

]]>*On 17/06/2005 at 10:27, xxxxxxxx wrote:*

Oh, you should have been more clear (point inside/within a polygon).

This is different (and more complex). :) You may need to have a look at 'texture sampling' algorithms to see how sample points on a UV plane are mapped to the 3D polygon and do the inverse. Since this is not a procedural mapping (spherical, conical, cylindrical etc.) there is no way to create a transformation matrix to expedite the transform. And Barycentric coords may not help. Good for sampling interpolation, but not for point transformation (as far as I know). If I'm not mistaken, there will be a bit of partial-derivative Calculus involved (dU/dV type).

]]>*On 17/06/2005 at 09:22, xxxxxxxx wrote:*

You misunderstood me. I have a point inside the polygon and need to find the uvw coordinate for this point! It´s not a vertex (position).

]]>*On 17/06/2005 at 09:17, xxxxxxxx wrote:*

You get the UVWStruct from the UVWTag (UVWTag->Get(i) where i is the polygon's index). UVWStruct contains Vectors (a,b,c,d). These Vectors are the UVW coordinates - not the XYZ coordinates - of the polygon's points.

]]>