Finding nearest uv?

Blitz3D Forums/Blitz3D Programming/Finding nearest uv?

AntonyWells(Posted 2004) [#1]
Say I had a point in 3d space. And a tri. How would I go about finding the nearest uv value to that point in 3d space, taken from that tri's own uv?(I.e mapped)

Similar to fredborg's linepick uv, but without needing it actually be a point on the tri..

At all possible or just wishful dreaming? :)


Skitchy(Posted 2004) [#2]
This might work ???
-Put a pivot at each point of the tri
-Get the distance from the test point to each pivot
-Calculate a 'ratio' between all 3 by averaging
-Grab the UV coords of each vert and apply the same ratio

That was my first thought anyway ;)


fredborg(Posted 2004) [#3]
Project the point onto the triangle, and use the PickedU etc. method.


AntonyWells(Posted 2004) [#4]
Skitch, my first thought too, although I'd prefer to see a already working method before I let myself loose on the sucker. ;)

Fredborg, I had this idea, but what I'm not sure of is how do I find the vector to project to? I mean this point in 3d space is always within the tri...so perhaps if I jused force feed your functions those values instead of pickedx,y,z?


fredborg(Posted 2004) [#5]
You obviously use the triangle normal for projection. If the point isn't located on the triangle the uv you get is incorrect.


Warren(Posted 2004) [#6]
You could move the point a few units along the triangles normal and then project it back...


AntonyWells(Posted 2004) [#7]
Yeah good point. Overthinking again.(Which in my case isn't the smartest idea)


AntonyWells(Posted 2004) [#8]
hey fred,

I didn't want to do linepicks, too slow for the amount of checks I need, so instead I force-feed it, the x,y,z position on the tri as picked,x,y,z, and the tri surface it's over, and finally as the normal I just passed the normazlied triangle normal. But I'm getting very messy results. I'm guessing this is because I need to pass the normal at each point on the tri rather than the constant tri norm...

that's assumg it would even be any diff...i doubt it because it's on it flat...

I wish I had paid attention at maths...


AntonyWells(Posted 2004) [#9]
never mind, I was passing the lumel position rather than the triangle normal by mistake..works fine now.