POV-Ray : Newsgroups : povray.advanced-users : Location changing while scaling Server Time
21 Nov 2024 12:30:22 EST (-0500)
  Location changing while scaling (Message 1 to 3 of 3)  
From: yesbird
Subject: Location changing while scaling
Date: 2 Sep 2024 05:39:26
Message: <66d587ce@news.povray.org>
Hi, all !

While playing with meshes I've encountered strange behavior of spheres, 
positioned at mesh vertices - after changing the scale they move from 
previous location (see images). Looks like the scale 
operation applied to a whole array of spheres, produced by loop, but the 
scale operator is inside the sphere object. I expected they would stay 
in place and only change the size.

What I'm missing ? Any suggestions please ...
--
YB

// ------------------------------------------------------------------
#version 3.8;
global_settings { assumed_gamma 1 }

camera {
   perspective
   angle 25
   location  <20,15,20> * 0.2
   look_at   <0.5,0.5,0>
   right x * image_width / image_height
}

light_source{<-500,0,0> rgb 1} light_source{<500,0,0> rgb 1}
light_source{<0,0,-500> rgb 1} light_source{<0,0,500> rgb 1}
light_source{<20,15,20> rgb 0.4}


#declare VertexVectors= array[24] {
   <0,0,0>, <0.5,0,0>, <0.5,0.5,0>, //1
   <0.5,0,0>, <1,0,0>, <0.5,0.5,0>, //2
   <1,0,0>, <1,0.5,0>, <0.5,0.5,0>, //3
   <1,0.5,0>, <1,1,0>, <0.5,0.5,0>, //4
   <1,1,0>, <0.5,1,0>, <0.5,0.5,0>, //5
   <0.5,1,0>, <0,1,0>, <0.5,0.5,0>, //6
   <0,1,0>, <0,0.5,0>, <0.5,0.5,0>, //7
   <0,0.5,0>, <0,0,0>, <0.5,0.5,0>  //8
}

// Mesh
mesh2 {

    #local len = dimension_size(VertexVectors,1);
    vertex_vectors {
       len,
   		#for (i, 0, len-1)
     		VertexVectors[i]
   		#end
    }

    face_indices {
       8,
       <0,1,2>,    <3,4,5>,       //1 2
       <6,7,8>,    <9,10,11>,     //3 4
       <12,13,14>, <15,16,17>,    //5 6
       <18,19,20>, <21,22,23>     //7 8
    }

    pigment {rgb 1}
}


// Spheres
#local len = dimension_size(VertexVectors,1) - 1;
#for (i, 0, len)
   sphere { VertexVectors[i], 0.04
            texture { pigment {rgb <0.1, 0.3, 0.1>} }
            scale y * 1.2 // Why they moves ?
   }
#end
// ------------------------------------------------------------------


Post a reply to this message


Attachments:
Download 'test_scale_no.png' (12 KB) Download 'test_scale_yes.png' (12 KB)

Preview of image 'test_scale_no.png'
test_scale_no.png

Preview of image 'test_scale_yes.png'
test_scale_yes.png


 

From: Alain Martel
Subject: Re: Location changing while scaling
Date: 2 Sep 2024 06:43:39
Message: <66d596db$1@news.povray.org>
Le 2024-09-02 à 05:39, yesbird a écrit :
> Hi, all !
> 
> While playing with meshes I've encountered strange behavior of spheres, 
> positioned at mesh vertices - after changing the scale they move from 
> previous location (see images). Looks like the scale 
> operation applied to a whole array of spheres, produced by loop, but the 
> scale operator is inside the sphere object. I expected they would stay 
> in place and only change the size.
> 
> What I'm missing ? Any suggestions please ...
> -- 
> YB
> 
> // ------------------------------------------------------------------
> #version 3.8;
> global_settings { assumed_gamma 1 }
> 
> camera {
>    perspective
>    angle 25
>    location  <20,15,20> * 0.2
>    look_at   <0.5,0.5,0>
>    right x * image_width / image_height
> }
> 
> light_source{<-500,0,0> rgb 1} light_source{<500,0,0> rgb 1}
> light_source{<0,0,-500> rgb 1} light_source{<0,0,500> rgb 1}
> light_source{<20,15,20> rgb 0.4}
> 
> 
> #declare VertexVectors= array[24] {
>    <0,0,0>, <0.5,0,0>, <0.5,0.5,0>, //1
>    <0.5,0,0>, <1,0,0>, <0.5,0.5,0>, //2
>    <1,0,0>, <1,0.5,0>, <0.5,0.5,0>, //3
>    <1,0.5,0>, <1,1,0>, <0.5,0.5,0>, //4
>    <1,1,0>, <0.5,1,0>, <0.5,0.5,0>, //5
>    <0.5,1,0>, <0,1,0>, <0.5,0.5,0>, //6
>    <0,1,0>, <0,0.5,0>, <0.5,0.5,0>, //7
>    <0,0.5,0>, <0,0,0>, <0.5,0.5,0>  //8
> }
> 
> // Mesh
> mesh2 {
> 
>     #local len = dimension_size(VertexVectors,1);
>     vertex_vectors {
>        len,
>            #for (i, 0, len-1)
>              VertexVectors[i]
>            #end
>     }
> 
>     face_indices {
>        8,
>        <0,1,2>,    <3,4,5>,       //1 2
>        <6,7,8>,    <9,10,11>,     //3 4
>        <12,13,14>, <15,16,17>,    //5 6
>        <18,19,20>, <21,22,23>     //7 8
>     }
> 
>     pigment {rgb 1}
> }
> 
> 
> // Spheres
> #local len = dimension_size(VertexVectors,1) - 1;
> #for (i, 0, len)
>    sphere { VertexVectors[i], 0.04
>             texture { pigment {rgb <0.1, 0.3, 0.1>} }
>             scale y * 1.2 // Why they moves ?
>    }
> #end
> // ------------------------------------------------------------------
The scale is applied relative to the origin of the coordinate system, 
not to the centre of the object.
That mean that the centre of your spheres are scaled.
You need to scale your spheres when they are at <0,0,0> then translate 
them to the desired location.

Use this instead :
// Spheres
#local len = dimension_size(VertexVectors,1) - 1;
#for (i, 0, len)
   sphere { 0, 0.04 scale y * 1.2 // No longer move
            texture { pigment {rgb <0.1, 0.3, 0.1>} }

	translate VertexVectors[i]
   }


Post a reply to this message

From: yesbird
Subject: Re: Location changing while scaling
Date: 2 Sep 2024 07:04:37
Message: <66d59bc5$1@news.povray.org>
On 02/09/2024 13:43, Alain Martel wrote:
> You need to scale your spheres when they are at <0,0,0> then translate 
> them to the desired location.
> 
> Use this instead :
> // Spheres
> #local len = dimension_size(VertexVectors,1) - 1;
> #for (i, 0, len)
>    sphere { 0, 0.04 scale y * 1.2 // No longer move
>             texture { pigment {rgb <0.1, 0.3, 0.1>} }
> 
>      translate VertexVectors[i]
>    }

Many thanks for elegant solution !
--
YB


Post a reply to this message

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