POV-Ray : Newsgroups : povray.general : shear matrix problem Server Time
29 Jul 2024 14:25:45 EDT (-0400)
  shear matrix problem (Message 1 to 10 of 12)  
Goto Latest 10 Messages Next 2 Messages >>>
From: Thomas de Groot
Subject: shear matrix problem
Date: 13 Jul 2011 08:21:28
Message: <4e1d8dc8$1@news.povray.org>
I confess that I do not really understand the working of a matrix. 
Consider the following piece of code:

//start code
#declare P1 = <-1.6, 0.0, 0>;
#declare P2 = < 1.6, 0.8,  0>;

#local Point =
sphere {
   <0,0,0>, 0.05
}

object {Point translate P1  pigment {rgb <1,0,0>}}
object {Point translate P2  pigment {rgb <1,1,0>}}

#declare Segment =
box {<-0.10, 0.00, -0.010>, <0.00, 1.00, 0.010>}

#local a = 0;
#local b = VDist(P1,P2);

union {
   #while (a <= b)
     object {Segment
       translate <0, a, 0>
       #if (even(a))
         pigment {rgb <0,1,0>}
       #else
         pigment {rgb <0,0,1>}
       #end
       #local a=a+1;
     }
   #end
   clipped_by {plane {y, b}}
   matrix <1, (P1.y-P2.y), 0, // matrix-shear_x_to_y
           0, 1, 0,
           0, 0, 1,
           0, 0, 0>
   Point_At_Trans(P2-P1)
   translate P1
}
//end code

What I want is that the short sides of the Segment always remain 
vertical whatever the positions of P1 or P2. What am I doing wrong?

Thanks for any help,

Thomas


Post a reply to this message

From: Roman Reiner
Subject: Re: shear matrix problem
Date: 13 Jul 2011 10:35:01
Message: <web.4e1dad017fd51405257ce790@news.povray.org>
I'm not quite sure what you are doing, so i can't tell you what you are doing
wrong.
My guess is, that you need to transpose the upper 3x3 portion of your matrix,
that is, use

matrix <1, 0, 0,
       (P1.y-P2.y), 1, 0,
       0, 0, 1,
       0, 0, 0>

instead.

You could also try the Shear_Trans() and/or Matrix_Trans() macros in
transforms.inc instead, which are probably easier to use.

Regards Roman



Thomas de Groot <tDOTdegrootATinterDOTnlDOTnet> wrote:
> I confess that I do not really understand the working of a matrix.
> Consider the following piece of code:
>
> //start code
> #declare P1 = <-1.6, 0.0, 0>;
> #declare P2 = < 1.6, 0.8,  0>;
>
> #local Point =
> sphere {
>    <0,0,0>, 0.05
> }
>
> object {Point translate P1  pigment {rgb <1,0,0>}}
> object {Point translate P2  pigment {rgb <1,1,0>}}
>
> #declare Segment =
> box {<-0.10, 0.00, -0.010>, <0.00, 1.00, 0.010>}
>
> #local a = 0;
> #local b = VDist(P1,P2);
>
> union {
>    #while (a <= b)
>      object {Segment
>        translate <0, a, 0>
>        #if (even(a))
>          pigment {rgb <0,1,0>}
>        #else
>          pigment {rgb <0,0,1>}
>        #end
>        #local a=a+1;
>      }
>    #end
>    clipped_by {plane {y, b}}
>    matrix <1, (P1.y-P2.y), 0, // matrix-shear_x_to_y
>            0, 1, 0,
>            0, 0, 1,
>            0, 0, 0>
>    Point_At_Trans(P2-P1)
>    translate P1
> }
> //end code
>
> What I want is that the short sides of the Segment always remain
> vertical whatever the positions of P1 or P2. What am I doing wrong?
>
> Thanks for any help,
>
> Thomas


Post a reply to this message

From: StephenS
Subject: Re: shear matrix problem
Date: 13 Jul 2011 17:10:00
Message: <web.4e1e08c27fd514019787f110@news.povray.org>
Thomas de Groot <tDOTdegrootATinterDOTnlDOTnet> wrote:
....
> What I want is that the short sides of the Segment always remain
> vertical whatever the positions of P1 or P2. What am I doing wrong?
>
> Thanks for any help,
>
> Thomas

Did you see the new winpov insert menu/Transformation/matrix_shear...
examples with pictures.

Do these help?

Stephen S


Post a reply to this message

From: Thomas de Groot
Subject: Re: shear matrix problem
Date: 14 Jul 2011 02:58:11
Message: <4e1e9383@news.povray.org>
On 13-7-2011 23:06, StephenS wrote:
> Thomas de Groot<tDOTdegrootATinterDOTnlDOTnet>  wrote:
> ....
>> What I want is that the short sides of the Segment always remain
>> vertical whatever the positions of P1 or P2. What am I doing wrong?
>>
>> Thanks for any help,
>>
>> Thomas
>
> Did you see the new winpov insert menu/Transformation/matrix_shear...
> examples with pictures.
>
> Do these help?
>
> Stephen S
>
>

Yes, that is basically where my matrix is coming from:
      matrix<1, 0.5, 0, // matrix-shear_x_to_y
             0,  1,  0,
             0,  0,  1,
             0,  0,  0>

The difficulty is that, not only the object at P1 needs to point_at P2, 
which is not difficult to do, but also has to be sheared in such a way 
that the short sides remain vertical.
Maybe I am making a wrong assumption somewhere....

THomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: shear matrix problem
Date: 14 Jul 2011 03:42:12
Message: <4e1e9dd4$1@news.povray.org>
No, the matrix is correct for shearing vertically, which is my 
intention, like from the Insert Menu:
   matrix <1, 0.5, 0, // matrix-shear_x_to_y
           0,  1,  0,
           0,  0,  1,
           0,  0,  0>
Where I am going wrong, I guess is by using Point_At_Trans(), instead of 
Reorient_Trans(). Still, I am not out of the wood :-(

I rewrote my code accordingly and I am sure it is the 0.5 in the matrix 
that should be replaced by a variable based on P1 and P2, but I am 
really at a loss what that should be.

Try this new code which is more towards what I intend to do:

//Start Code
#local P1 = <-1.6, 0.1, 0>;
#local P2 = < 1.7, 1.5, 0>;

#local Point =
sphere {
   <0,0,0>, 0.05
}

object {Point}
object {Point translate P1  pigment {rgb <1,0,0>}}
object {Point translate P2  pigment {rgb <1,1,0>}}

#local Segment =
box {<0.00, 0.00, -0.010>, <1.00, 0.10, 0.010>}

#local a = 0;
#local b = VDist(P1,P2);

union {
   #while (a < b)
     object {Segment
       translate <a, 0, 0>
       #if (even(a))
         pigment {rgb <0,1,0>}
       #else
         pigment {rgb <0,0,1>}
       #end
       #local a=a+1;
     }
   #end
   clipped_by {plane {x, b}}
   matrix <1, 0.5, 0, // matrix-shear_x_to_y
           0,  1,  0,
           0,  0,  1,
           0,  0,  0>
   Reorient_Trans (<P1.x,0,P1.z>, <-P2.x, 0, -P2.z>)
   translate P1
}
//End Code

If you increase or decrease the 0.5 value, you will see the shearing 
increasing or decreasing, while the short sides remain vertical like I 
want. Only, now the problem is to keep the object's far end at the P2 
location :-(

The info about Shear_Trans() and Matrix_Trans() is so succinct (for me) 
that I cannot do anything with it. My math knowledge is clearly to low 
for this.

Thomas

On 13-7-2011 16:34, Roman Reiner wrote:
> I'm not quite sure what you are doing, so i can't tell you what you are doing
> wrong.
> My guess is, that you need to transpose the upper 3x3 portion of your matrix,
> that is, use
>
> matrix<1, 0, 0,
>         (P1.y-P2.y), 1, 0,
>         0, 0, 1,
>         0, 0, 0>
>
> instead.
>
> You could also try the Shear_Trans() and/or Matrix_Trans() macros in
> transforms.inc instead, which are probably easier to use.
>
> Regards Roman
>


Post a reply to this message

From: Roman Reiner
Subject: Re: shear matrix problem
Date: 14 Jul 2011 04:55:00
Message: <web.4e1eaeba7fd51405257ce790@news.povray.org>
Like this?

//Start Code
#local P1 = <-1.6, 0.1, 0>;
#local P2 = < 1.7, 1.5, 0>;

#local Point =
sphere {
   <0,0,0>, 0.05
   pigment { rgb 1 }
}

object {Point}
object {Point translate P1  pigment {rgb <1,0,0>}}
object {Point translate P2  pigment {rgb <1,1,0>}}

#local Segment =
box {<0.00, 0.00, -0.010>, <1.00, 0.10, 0.010>}

#declare d = P2-P1;

#local a = 0;
#local b = d.x;

union {
   #while (a < b)
     object {Segment
       translate <a, 0, 0>
       #if (mod(a,2)=0)
         pigment {rgb <0,1,0>}
       #else
         pigment {rgb <0,0,1>}
       #end
       #local a=a+1;
     }
   #end
   clipped_by {plane {x, b}}
   matrix <d.x/b,  d.y/b,  0, // matrix-shear_x_to_y
           0,  1,  0,
           0,  0,  1,
           0,  0,  0>
   translate P1
}
//End Code


Post a reply to this message

From: Roman Reiner
Subject: Re: shear matrix problem
Date: 14 Jul 2011 05:10:01
Message: <web.4e1eb1907fd51405257ce790@news.povray.org>
BTW, i killed that Reorient_Trans since it does nothing. As P1.z and P2.z are
zero those two: <P1.x,0,P1.z>, <-P2.x, 0, -P2.z> are parallel (pointing in
opposite directions) resulting in the Reorient_Trans macro to return an empty
transform.

Regards Roman


Post a reply to this message

From: Thomas de Groot
Subject: Re: shear matrix problem
Date: 14 Jul 2011 07:20:30
Message: <4e1ed0fe$1@news.povray.org>
On 14-7-2011 11:06, Roman Reiner wrote:
> BTW, i killed that Reorient_Trans since it does nothing. As P1.z and P2.z are
> zero those two:<P1.x,0,P1.z>,<-P2.x, 0, -P2.z>  are parallel (pointing in
> opposite directions) resulting in the Reorient_Trans macro to return an empty
> transform.
>
> Regards Roman
>
>

Yes, that works, but only because z remains 0 in your code. That is why 
I am not too sure about not using VDist(). The Reorient_Trans() is 
necessary for those cases where P2 (and/or P1) moves also along the 
z-axis. Or is there another way? The code should be valid for *all* 3D 
locations of P1 and P2.

Thomas


Post a reply to this message

From: Roman Reiner
Subject: Re: shear matrix problem
Date: 14 Jul 2011 08:10:00
Message: <web.4e1edc227fd51405257ce790@news.povray.org>
In that case it should read Reorient_Trans(<1,0,0>, <d.x, 0, d.z>) where d is,
again, P2-P1.

Also b = d.x needs to be replaced with b = vlength(<d.x, 0, d.z>).

Altogether:

//Start Code
#local P1 = <-1.6, 0.1, -.5>;
#local P2 = < 1.7, 1.5, 1>;

#local Point =
sphere {
   <0,0,0>, 0.05
   pigment { rgb 1 }
}

object {Point}
object {Point translate P1  pigment {rgb <1,0,0>}}
object {Point translate P2  pigment {rgb <1,1,0>}}

#local Segment =
box {<0.00, 0.00, -0.010>, <1.00, 0.10, 0.010>}

#declare d = P2-P1;

#local a = 0;
#local b = vlength(<d.x, 0, d.z>);
union {
   #while (a < b)
     object {Segment
       translate <a, 0, 0>
       #if (mod(a,2)=0)
         pigment {rgb <0,1,0>}
       #else
         pigment {rgb <0,0,1>}
       #end
       #local a=a+1;
     }
   #end
   clipped_by {plane {x, b}}
   matrix <1  d.y/b,  0,
           0,  1,  0,
           0,  0,  1,
           0,  0,  0>
   Reorient_Trans(x, d*(1-y)) //short for Reorient_Trans(<1,0,0>, <d.x, 0, d.z>)
   translate P1
}
//End Code

[Note, that the above version shears the segments by dragging the far end up
resulting in the originally unit length segments to get longer. If you want them
to remain at unit length you need to use

   clipped_by {plane {x, vlength(d)}}
   matrix <b/vlength(d)  d.y/vlength(d),  0,
           0,  1,  0,
           0,  0,  1,
           0,  0,  0>

instead.]

Feel free to ask if you need any explanations!
Regards Roman

Thomas de Groot <tenDOTlnDOTretniATtoorgedDOTt> wrote:
> Yes, that works, but only because z remains 0 in your code. That is why
> I am not too sure about not using VDist(). The Reorient_Trans() is
> necessary for those cases where P2 (and/or P1) moves also along the
> z-axis. Or is there another way? The code should be valid for *all* 3D
> locations of P1 and P2.
>
> Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: shear matrix problem
Date: 14 Jul 2011 10:22:42
Message: <4e1efbb2@news.povray.org>
Thank you Roman, for your help! This works fine.

One question: you use vlength() instead of VDist() and seem not to take 
into account the y-component. However, it seems to me that between P1 
and P2 the y-component can potentially be of importance especially if 
height differences are large. Would that not be compensated by VDist()? 
Or vlength(d)?

Thomas

On 14-7-2011 14:08, Roman Reiner wrote:
> In that case it should read Reorient_Trans(<1,0,0>,<d.x, 0, d.z>) where d is,
> again, P2-P1.
>
> Also b = d.x needs to be replaced with b = vlength(<d.x, 0, d.z>).
>
> Altogether:
>
> //Start Code
> #local P1 =<-1.6, 0.1, -.5>;
> #local P2 =<  1.7, 1.5, 1>;
>
> #local Point =
> sphere {
>     <0,0,0>, 0.05
>     pigment { rgb 1 }
> }
>
> object {Point}
> object {Point translate P1  pigment {rgb<1,0,0>}}
> object {Point translate P2  pigment {rgb<1,1,0>}}
>
> #local Segment =
> box {<0.00, 0.00, -0.010>,<1.00, 0.10, 0.010>}
>
> #declare d = P2-P1;
>
> #local a = 0;
> #local b = vlength(<d.x, 0, d.z>);
> union {
>     #while (a<  b)
>       object {Segment
>         translate<a, 0, 0>
>         #if (mod(a,2)=0)
>           pigment {rgb<0,1,0>}
>         #else
>           pigment {rgb<0,0,1>}
>         #end
>         #local a=a+1;
>       }
>     #end
>     clipped_by {plane {x, b}}
>     matrix<1  d.y/b,  0,
>             0,  1,  0,
>             0,  0,  1,
>             0,  0,  0>
>     Reorient_Trans(x, d*(1-y)) //short for Reorient_Trans(<1,0,0>,<d.x, 0, d.z>)
>     translate P1
> }
> //End Code
>
> [Note, that the above version shears the segments by dragging the far end up
> resulting in the originally unit length segments to get longer. If you want them
> to remain at unit length you need to use
>
>     clipped_by {plane {x, vlength(d)}}
>     matrix<b/vlength(d)  d.y/vlength(d),  0,
>             0,  1,  0,
>             0,  0,  1,
>             0,  0,  0>
>
> instead.]
>
> Feel free to ask if you need any explanations!
> Regards Roman


Post a reply to this message

Goto Latest 10 Messages Next 2 Messages >>>

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