POV-Ray : Newsgroups : povray.newusers : Loop with logical expressions Server Time
29 Apr 2024 02:13:42 EDT (-0400)
  Loop with logical expressions (Message 1 to 2 of 2)  
From: Bald Eagle
Subject: Loop with logical expressions
Date: 19 Mar 2014 15:55:45
Message: <5329f641$1@news.povray.org>
I seem to be having difficulties predicting the results of this loop.
I _wanted_ to get a matrix of holes that were 3,5,7,7,7,5,3 in both the 
X and Y directions, but I get 4 extra holes on the top row - ("top" 
before z-rotation)

[object T30H is just a cylinder place-holder for a mounting screw]

Is there an obvious error someone can point out?
Thanks,


#declare Intercom_Button = union {
	difference {
		box {<0, 0, 0>, <5, 5, -0.125> pigment {Gray80} }
		union {
			#declare Holes = 0.429;
			#declare X=1;
			#while (X<8)
			#declare Y=1;
			#while (Y<8)
				#if (Y=1 & (X<3 | X>5) )
				#declare Y=Y+1;
				#end
				#if (Y=2 & (X=1 | X=7) )
				#declare Y=Y+1;
				#end
				#if (Y=6 & (X=1 | X=7) )
				#declare Y=Y+1;
				#end
				#if (Y=7 & (X<3 | X>5) )
				#declare Y=Y+1;
				#end
				
				cylinder {<X*Holes, Y*Holes, -0.25>, <X*Holes, Y*Holes, 0.25>, 0.125 
pigment {Black}}
			#declare Y=Y+1;
			#end
			#declare X=X+1;
			#end
			rotate z*45 translate x*1.75}
		}
	sphere { <4, 2, 0>, 0.5 pigment {Gray50} }
	object {T30H translate <0.5, 0.5, -0.125>}
	object {T30H translate <0.5, 4.5, -0.125>}
	object {T30H translate <4.5, 0.5, -0.125>}
	object {T30H translate <4.5, 4.5, -0.125>}
		}


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Loop with logical expressions
Date: 19 Mar 2014 19:47:45
Message: <532a2ca1$1@news.povray.org>
On 19.03.2014 20:55, Bald Eagle wrote:

> I seem to be having difficulties predicting the results of this loop.

Note that for the case (Y=7 & (X<3 | X>5) ) you increase Y to "skip"
but still add the cylinder at Y = 8.

In general increasing a loop counter arbitrarily during the loop
is error-prone. A better way to write might be

  #if ( !( (Y=1 | Y=7) & (X<3 | X>5) ) &
      ( !( (Y=2 | Y=6) & (X=1 | X=7) ) )
   cylinder
  #end


Post a reply to this message

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