POV-Ray : Newsgroups : povray.general : shear matrix problem Server Time
29 Jul 2024 16:32:46 EDT (-0400)
  shear matrix problem (Message 3 to 12 of 12)  
<<< Previous 2 Messages Goto Initial 10 Messages
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

From: Roman Reiner
Subject: Re: shear matrix problem
Date: 14 Jul 2011 10:50:01
Message: <web.4e1f01a97fd5140b9e1fc8c0@news.povray.org>
VDist(P1,P2) is just short (as if ;)) for vlength(P2-P1), i prefer the latter
because it saves me an #include but it doesn't really make a difference.

I *am* taking the y-component into account:
Basically I work with the rectangular triangle with vertices P1, P1+<d.x, 0,
d.z> and P1+<d.x, d.y, d.z> = P1+d = P2. (draw a picture if you need to). The
ratio of the length of the horizontal component (vlength(<d.x, 0, d.z>) = b) and
the length of the vertical component (d.y) determine the shear matrix.

The actual distance length(d) appears in the second version as a normalization
constant. In the first version it does not appear explicitly, but mathematically
it is still in there somewhere as it is well defined by the lengths b and d.y
via phytagoras.

Regards Roman


Thomas de Groot <tenDOTlnDOTretniATtoorgedDOTt> wrote:
> 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


Post a reply to this message

From: Thomas de Groot
Subject: Re: shear matrix problem
Date: 14 Jul 2011 10:55:42
Message: <4e1f036e$1@news.povray.org>
Again, Thank you indeed Roman. I shall study this more in depth later on 
in order to understand it better.

See in p.b.i. for the application of your code :-)

Thomas

On 14-7-2011 16:48, Roman Reiner wrote:
> VDist(P1,P2) is just short (as if ;)) for vlength(P2-P1), i prefer the latter
> because it saves me an #include but it doesn't really make a difference.
>
> I *am* taking the y-component into account:
> Basically I work with the rectangular triangle with vertices P1, P1+<d.x, 0,
> d.z>  and P1+<d.x, d.y, d.z>  = P1+d = P2. (draw a picture if you need to). The
> ratio of the length of the horizontal component (vlength(<d.x, 0, d.z>) = b) and
> the length of the vertical component (d.y) determine the shear matrix.
>
> The actual distance length(d) appears in the second version as a normalization
> constant. In the first version it does not appear explicitly, but mathematically
> it is still in there somewhere as it is well defined by the lengths b and d.y
> via phytagoras.
>
> Regards Roman
>
>
> Thomas de Groot<tenDOTlnDOTretniATtoorgedDOTt>  wrote:
>> 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
>
>
>


Post a reply to this message

<<< Previous 2 Messages Goto Initial 10 Messages

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