POV-Ray : Newsgroups : povray.bugreports : uv_mapping bug on cylinders : Re: uv_mapping bug on cylinders Server Time 2 Dec 2023 19:20:54 EST (-0500)
 Re: uv_mapping bug on cylinders
 From: Bald Eagle Date: 4 Aug 2022 06:40:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.62eba114f9bd2f341f9dae3025979125%40news.povray.org",
"headline": "Re: uv_mapping bug on cylinders",
"dateCreated": "2022-08-04T10:40:00+00:00",
"datePublished": "2022-08-04T10:40:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
Thomas de Groot <tho### [at] degrootorg> wrote:
> ...which reminds me to ask you (curiosity): how does
>
> #declare U = function (X, Y, Z) {(0.5 + atan2 (N(Z, X,Y,Z), N(X,
> X,Y,Z))/(2*pi))}
> #declare V = function (X, Y, Z) {(0.5 + asin(N(Y, X,Y,Z))/pi)}
>
> work? is puzzling, as far as atan2 and asin are concerned.
>
> --
> Thomas

I don't have the file accessible to me ATM, but IIRC, the N() function is
probably just a select () for whichever vector component is specified as the
first argument. (*)

Then the atan2 returns an angle between -pi and pi, based on z and x.
Dividing by tau gives values between -0.5 and 0.5, and then everything is
shifted to between 0 and 1.

asin returns an angle between -pi/2 and pi/2.
Dividing by pi gives values between -0.5 and 0.5, and then everything is shifted
to between 0 and 1.

(*) And the way THAT works, is taking the specified vector components and doing
something like x*(-1) + y*0 + z*(2).  That should give you a -1, a 0, or a 2
depending on which cardinal vector is specified.
select () then returns one of three scalar values depending on what component it
spits out.
```