POV-Ray : Newsgroups : povray.general : Projective transform matrix Server Time
31 Jul 2024 14:22:00 EDT (-0400)
  Projective transform matrix (Message 1 to 8 of 8)  
From: Benoit
Subject: Projective transform matrix
Date: 18 Feb 2007 19:15:01
Message: <web.45d8eb5a729f303f3d2ece630@news.povray.org>
Hi All,

The "matrix" construct allows one to enter a matrix for a 3D affine
transform. Internally, however, what is stored and used is a linear
transform in the 4D projective space. The 4x4 matrix used for internal
purposes is composed of the 12 coefficients provided by the user in the
"matrix" construct, plus "0 0 0 1" for the last line.

Is there any way that one could enter directly the 16 coefficients of the 4D
projective transform? This would for example enable the transformation of
cylindrical elements into cones, or more complex elements (e.g. height
fields) into their cone version...

Thanks

Benoit


Post a reply to this message

From: John VanSickle
Subject: Re: Projective transform matrix
Date: 18 Feb 2007 19:46:29
Message: <45d8f365$1@news.povray.org>
Benoit wrote:
> Hi All,
> 
> The "matrix" construct allows one to enter a matrix for a 3D affine
> transform. Internally, however, what is stored and used is a linear
> transform in the 4D projective space. The 4x4 matrix used for internal
> purposes is composed of the 12 coefficients provided by the user in the
> "matrix" construct, plus "0 0 0 1" for the last line.
> 
> Is there any way that one could enter directly the 16 coefficients of the 4D
> projective transform? This would for example enable the transformation of
> cylindrical elements into cones, or more complex elements (e.g. height
> fields) into their cone version...

No.  The type of transformation you describe is non-linear, which is not 
within the capability of any ordinary matrix.

The main problem with using a non-linear transform in POV-Ray is that a 
non-linear transform can have more than one inverse, or possibly no 
inverse, and POV-Ray requires its transforms to have exactly one 
inverse.  (This is also the reason that a scaling value of zero results 
in an error; such matrices have no inverse.)

OpenGL (and other renderers), make use of the full 4x4 matrix, because 
they use the camera transform to to perspective calculations as well as 
to transform the camera space into screen coordinates.  The vector 
<x,y,z,1> is fed to the camera matrix, resulting in a new vector 
<x',y',z',w>.

The perspective effect is achieved by dividing w into x', y', and z'. 
The projection matrix is designed so that objects that are farther away 
from the camera will have a higher value for w, and objects that are 
closer will have a lower value.  This usually involves a fourth column 
of the form <a,b,c,0>.  Dividing the w into the rest of the vector 
causes the father objects to be smaller then the closer ones.

When the matrix is an orthographic projection, the fourth column is the 
same constant <0,0,0,1> as POV-Ray uses for its object transformations; 
as a consequence, the w value is always 1, and as a consequence objects 
do not change in screen dimensions as they move closer or farther away 
from the camera viewpoint.

The scale, rotate, and translate transforms have no need for this 
normalization step, and so the fourth column is always the constant 
value you mention, and remains so no matter how many transforms are applied.

Hope this helps,
John


Post a reply to this message

From: Benoit
Subject: Re: Projective transform matrix
Date: 18 Feb 2007 20:25:03
Message: <web.45d8fc32c7fb0e2d3d2ece630@news.povray.org>
> Hope this helps,
> John

Many thanks
Benoit


Post a reply to this message

From: Warp
Subject: Re: Projective transform matrix
Date: 19 Feb 2007 03:33:20
Message: <45d960d0@news.povray.org>
John VanSickle <evi### [at] hotmailcom> wrote:
> The main problem with using a non-linear transform in POV-Ray is that a 
> non-linear transform can have more than one inverse, or possibly no 
> inverse, and POV-Ray requires its transforms to have exactly one 
> inverse.  (This is also the reason that a scaling value of zero results 
> in an error; such matrices have no inverse.)

  All POV-Ray users are used to thinking that when the specify a
transformation (such as rotate, scale and translate) they are actually
transforming the object itself. In other words, it's the object itself
which moves and changes orientation and shape.

  In fact, that's actually true for a limited number of cases. For example,
if you translate a sphere, what POV-Ray does is to simply move the center
of the sphere and that's it. In this case the transformation was really
a modification of the object. However, this was just a special case done
for efficiency because it's easy to do.

  However, other transformations are not so easy to apply directly to the
object. For instance, suppose you apply "scale <1, 0.25, 1> rotate z*35"
to the sphere. Suddenly the sphere was converted into an ellipsoid and,
what's worse, its axes are not parallel to the main axes anymore. The
equation of such an ellipsoid suddenly became a whole lot more complicated
than that the one of a sphere.
  Now skew this ellipsoid by further applying an additional
"scale <1, 0.5, 1>" and suddenly you have an irregular shape which
formula is even more complicated.

  With a sphere it might even be theoretically possible to apply all
these transformations directly to it, using different formulas for
different possible shapes. However, think about more complex surfaces
such as torii, superellipsoids or 4D julia fractals. It quickly becomes
prohibitively hard.

  It becomes clear that applying the transformation to the object itself
is not possible in the general case. So how does POV-Ray do it?

  Well, the clever trick is that instead of modifying the object, what
is modified is the *ray* which tests the intersection against that object.
More specifically, instead of applying the transformation to the object,
the inverse transformation is applied to the ray instead. This allows
very easily and in a general way to apply any such transformation to
any object which is raytraceable.

  Of course there's a catch: The inverse transformation must exist, and
it must be linear. The ray must remain straight after the transformation.
Raytracing with curved rays is prohitively difficult and slow.

  That's the reason why non-linear transformations are so difficult.
They would require raytracing with curved lines, which would be slow
and error-prone.

-- 
                                                          - Warp


Post a reply to this message

From: Thomas de Groot
Subject: Re: Projective transform matrix
Date: 19 Feb 2007 07:17:57
Message: <45d99575$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> schreef in bericht 
news:45d960d0@news.povray.org...
>
>  All POV-Ray users are used to thinking that when the specify a
> transformation (such as rotate, scale and translate) they are actually
> transforming the object itself. In other words, it's the object itself
> which moves and changes orientation and shape.
> etc....


Wow!!
Have I now learned something! This is really news for me! Thank you, Warp, 
for this explanation.

Thomas


Post a reply to this message

From: John VanSickle
Subject: Re: Projective transform matrix
Date: 19 Feb 2007 11:35:44
Message: <45d9d1e0$1@news.povray.org>
Warp wrote:
> John VanSickle <evi### [at] hotmailcom> wrote:
> 
>>The main problem with using a non-linear transform in POV-Ray is that a 
>>non-linear transform can have more than one inverse, or possibly no 
>>inverse, and POV-Ray requires its transforms to have exactly one 
>>inverse.  (This is also the reason that a scaling value of zero results 
>>in an error; such matrices have no inverse.)
> 
>   All POV-Ray users are used to thinking that when the specify a
> transformation (such as rotate, scale and translate) they are actually
> transforming the object itself. In other words, it's the object itself
> which moves and changes orientation and shape.
> 
>   In fact, that's actually true for a limited number of cases. For example,
> if you translate a sphere, what POV-Ray does is to simply move the center
> of the sphere and that's it. In this case the transformation was really
> a modification of the object. However, this was just a special case done
> for efficiency because it's easy to do.

Actually, I had always thought that the inverse of the transform was 
applied to the ray used for ray-object calculations, which accomplishes 
the same thing.

I can see that sometimes the forward transform is needed for things like 
texturing, etc.

I don't snoop through the POV-Ray sources, so this may all be blarney.

Regards,
John


Post a reply to this message

From: Grassblade
Subject: Re: Projective transform matrix
Date: 19 Feb 2007 16:45:00
Message: <web.45da1932c7fb0e2dd65915900@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:

>   Of course there's a catch: The inverse transformation must exist, and
> it must be linear. The ray must remain straight after the transformation.
> Raytracing with curved rays is prohitively difficult and slow.
>
>   That's the reason why non-linear transformations are so difficult.
> They would require raytracing with curved lines, which would be slow
> and error-prone.
>
> --
>                                                           - Warp
Hmm, but wouldn't it be straightforward to keep the transformation matrix
linear and have the ray vector be an easy to invert non-linear
transformation? E.g.
(a11 a12 a13)(x^2)
(a21 a22 a23)(y^3)
(a31 a32 a33)(z)


Post a reply to this message

From: Warp
Subject: Re: Projective transform matrix
Date: 19 Feb 2007 17:27:31
Message: <45da2453@news.povray.org>
Grassblade <nomail@nomail> wrote:
> Hmm, but wouldn't it be straightforward to keep the transformation matrix
> linear and have the ray vector be an easy to invert non-linear
> transformation? E.g.
> (a11 a12 a13)(x^2)
> (a21 a22 a23)(y^3)
> (a31 a32 a33)(z)

  Whichever transformation you apply to the ray, it must be kept a
straight line. There's no way around it.

  Of course you may be thinking: "Ok, even though each ray is kept
straight, what stops me from applying *different* transformations
to each ray instead of applying the exact same to all of them?"

  Good question. You can perform all kinds of transformations to individual
rays, of course. In fact, if you want to play with that, you can already
do that in a whole-scene level: You can add a "normal" block to the camera
which will transform the rays in a non-linear fashion (ie. each ray can
be transformed completely differently from the other rays).

  The problem with this is that it's not very useful. It's only useful
for special effects, but not to transform objects. You are basically
distorting the projected image of the object, not the object.

  For example, suppose you have a camera at -z*10 and looking at the origin,
and a cylinder { -y, y, 1 }.
  You can transform the camera rays in such a way that the cylinder will
appear to actually be a cone.
  Great? Non-linear transformations, here we come?

  Unfortunately not. Now apply a "rotate x*45" to the cylinder: Oops!
It's not the same kind of cone anymore. It's distorted, but quite
differently from before, and it doesn't look like a regular cone any
longer.
  In fact (AFAIK) there's no possible set of transformations which could
be done to the rays in order to make the cylinder still look like a
regular cone in this case.

  In other words, by perturbing the rays in certain ways you can distort
objects, but these distortions are not stable. They depend on the
orientation of the object. Rotate the object, and it distorts differently.
It's not possible to transform the rays in such way that a certain
distortion will keep stable regardless of the orientation of the object.
  As said, it can be used for some special effects, but unfortunately it
doesn't work as a transformation.

-- 
                                                          - Warp


Post a reply to this message

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