POV-Ray : Newsgroups : povray.general : Some UV math Server Time
5 Nov 2024 03:18:32 EST (-0500)
  Some UV math (Message 1 to 4 of 4)  
From: Peter Popov
Subject: Some UV math
Date: 6 Aug 1999 02:55:08
Message: <37ab85db.3283965@204.213.191.228>
Can anyone tell me the matrix to transform a given triangle into
another given triangle? I need this for some UV mapping stuff in POV
(not UVPOV :) ). TIA.


Peter Popov
ICQ: 15002700


Post a reply to this message

From: Nieminen Mika
Subject: Re: Some UV math
Date: 6 Aug 1999 03:39:21
Message: <37aa9129@news.povray.org>
Peter Popov <pet### [at] usanet> wrote:
: Can anyone tell me the matrix to transform a given triangle into
: another given triangle? I need this for some UV mapping stuff in POV
: (not UVPOV :) ). TIA.

  If http://users.erols.com/vansickl/matrix.htm doesn't help, you could ask
the author of that page himself. I'm sure he knows the answer.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: John VanSickle
Subject: Re: Some UV math
Date: 6 Aug 1999 17:23:54
Message: <37AB555F.ED16579@erols.com>
Nieminen Mika wrote:
> 
> Peter Popov <pet### [at] usanet> wrote:
> : Can anyone tell me the matrix to transform a given triangle into
> : another given triangle? I need this for some UV mapping stuff in POV
> : (not UVPOV :) ). TIA.
> 
>   If http://users.erols.com/vansickl/matrix.htm doesn't help, you
> could ask the author of that page himself. I'm sure he knows the
> answer.

"Look!  It's a vector!"
"It's a tensor!"
"No!  It's MATRIX MAN!

The exact formula isn't on the page, because I hadn't gotten around to
figuring it out.  After reading your message I sat down and wrote a
macro that will transform a triangle from one place to another.  I've
tested the code and it seems to work.

To use it, you define a triangle at a given set of points, and use the
macro to move it:

triangle { A,B,C
  texture { MyTexture }
  TransformTriangle(A,B,C,D,E,F)
}

If you want to declare the triangle at its final destination, and
only transform the texture, this will work as well:

triangle { D,E,F
  texture { MyTexture
    TransformTriangle(A,B,C,D,E,F)
  }
}

If you have a triangle somewhere in space and you want to slap
an image_map onto it, so that one corner of the image map is in each of
the corners of the triangle, this might be what you want:

triangle { A,B,C
  texture {
    pigment { image_map { gif "mygif.gif" }
      TransformTriangle(0,x,y,A,B,C)
    }
  }
}

Here's the macro code.  Put it into your favorite macro file:

// START OF MACRO CODE
// this macro creates the matrix that will transform triangle
// (A,B,C) into triangle (D,E,F).  Basically it's a matrix inversion,
// followed by the application of another matrix.

#macro TransformTriangle(pA,pB,pC,pD,pE,pF)

#local vXa=(pB-(pA));
#local vYa=(pC-(pA));
#local vZa=vcross(vXa,vYa);
// #local vLa=pA;

#local vXb=(pE-(pD));
#local vYb=(pF-(pD));
#local vZb=vcross(vXb,vYb);

#local sDET=vdot(vZa,vcross(vXa,vYa));

// these next three lines calculate the values for the inverted
// matrix:
#local vCX=vcross(vYa,vZa)/sDET;
#local vCY=vcross(vZa,vXa)/sDET;
#local vCZ=vcross(vXa,vYa)/sDET;

// these two steps take the triangle at (A,B,C) and move it to
// (<0,0,0>,x,y)
  translate -(pA)
  matrix <  vCX.x,vCY.x,vCZ.x,
            vCX.y,vCY.y,vCZ.y,
            vCX.z,vCY.z,vCZ.z,
                0,    0,    0  >

// this matrix takes the triangle at (<0,0,0>,x,y) and moves it
// to (D,E,F)

  matrix <  vXb.x,vXb.y,vXb.z,
            vYb.x,vYb.y,vYb.z,
            vZb.x,vZb.y,vZb.z,
             pD.x, pD.y, pD.z  >
#end

// END OF MACRO CODE

I think it's time to update the Throughly Useful Macros file...

Hope this helps,
John


Post a reply to this message

From: Peter Popov
Subject: Re: Some UV math
Date: 7 Aug 1999 14:08:32
Message: <37acab6e.3389798@204.213.191.228>
On Fri, 06 Aug 1999 17:36:31 -0400, John VanSickle
<van### [at] erolscom> wrote:

<snip>

>Hope this helps,
>John

You bet! Thank you.


Peter Popov
ICQ: 15002700


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.