POV-Ray : Newsgroups : povray.general : looking for a box macro Server Time
7 Aug 2024 19:23:53 EDT (-0400)
  looking for a box macro (Message 1 to 9 of 9)  
From: Rich
Subject: looking for a box macro
Date: 2 Jun 2001 14:17:19
Message: <Xns90B47D08D42AAspammindspringcom@204.213.191.228>
Hello,
    	What I'm looking for is a macro that will let me specify a height, a 
width, and two end points, and which then generates a box of the 
appropriate position and orientation.  Basically, I'm looking for a box 
object that works like the cylinder object, with end points instead of 
opposite corners.
    	I'm trying to make a castle, ya know?  <smile>  I have a bunch of 
cylinders with their axis along y, and I need to connect them with walls.  
So, I have the center points of the cylinders, and a lack of the math 
necessary to come up with the box corners to make the walls.  <sigh>  I'm 
hoping someone has already done this and I can be pointed at a URL, but I'm 
willing to write the Macro myself if someone can help me out with the math.

-- 
Rich Allen
(Remove SPAM from my address to reply by e-mail)


Post a reply to this message

From: Warp
Subject: Re: looking for a box macro
Date: 3 Jun 2001 16:36:24
Message: <3b1a9fc8@news.povray.org>
#macro Box(Point1, Point2, Width, Height, Rotation)
  #local Len = vlength(Point2-Point1);
  #local Dir = vnormalize(Point2-Point1);
  box
  { <-Width/2, 0, -Height/2>, <Width/2, Len, Height/2>
    rotate y*Rotation
    #local VY=vcross(Dir,y);
    #if(vlength(VY)>0)
      #local VY=vnormalize(VY);
      #local VZ1=vcross(VY,y);
      #local VZ2=vcross(VY,Dir);
      matrix <     0, VY.x, VZ1.x,
                   1, VY.y, VZ1.y,
                   0, VY.z, VZ1.z,
                   0,    0,     0 >
      matrix < Dir.x, Dir.y, Dir.z,
                VY.x,  VY.y,  VY.z,
               VZ2.x, VZ2.y, VZ2.z,
                   0,     0,     0 >
    #end
    translate Point1
  }
#end


-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Rich
Subject: Re: looking for a box macro
Date: 3 Jun 2001 21:29:12
Message: <Xns90B5C64211218spammindspringcom@204.213.191.228>
Warp <war### [at] tagpovrayorg> wrote in <3b1a9fc8@news.povray.org>:

> #macro Box(Point1, Point2, Width, Height, Rotation)

  Excellent, thank you VERY much!  I'm trying it out now.

-- 
Rich Allen
(Remove SPAM from my address to reply by e-mail)


Post a reply to this message

From: Rich
Subject: Re: looking for a box macro
Date: 3 Jun 2001 23:01:43
Message: <Xns90B5D5F09D985spammindspringcom@204.213.191.228>
SrP### [at] ricoswebcom (Rich) wrote in
<Xns90B5C64211218spammindspringcom@204.213.191.228>:

> Warp <war### [at] tagpovrayorg> wrote in <3b1a9fc8@news.povray.org>:
> 
>> #macro Box(Point1, Point2, Width, Height, Rotation)
> 
>   Excellent, thank you VERY much!  I'm trying it out now.
> 

Unfortunately, most of the boxes are rotated incorrectly along their length,
depending on the angle between the points I'm assuming.  Here is a sample
scene showing what I mean:

//----------------
camera {
  location  <0.0, 3.0, -6.000001>
  //location  <0.0, 10.0, -0.000001>
  direction 1.5*z
  right     4/3*x
  look_at   <0.0, 2.0,  0.0>
}

light_source { <-3, 30, -3> color rgb 1.5 }

#macro Wall(Point1, Point2, Width, Height, Rotation)
  #local Len = vlength(Point2-Point1);
  #local Dir = vnormalize(Point2-Point1);
  box
  { <-Width/2, 0, 0>, <Width/2, Len, Height>
    rotate y*Rotation
    #local VY=vcross(Dir,y);
    #if(vlength(VY)>0)
      #local VY=vnormalize(VY);
      #local VZ1=vcross(VY,y);
      #local VZ2=vcross(VY,Dir);
      matrix <     0, VY.x, VZ1.x,
                   1, VY.y, VZ1.y,
                   0, VY.z, VZ1.z,
                   0,    0,     0 >
      matrix < Dir.x, Dir.y, Dir.z,
                VY.x,  VY.y,  VY.z,
               VZ2.x, VZ2.y, VZ2.z,
                   0,     0,     0 >
    #end
    pigment { color rgb .5 }
    translate Point1
  }
#end

sky_sphere {
  pigment {
    gradient y
    color_map { [0.0 color blue 0.6] [1.0 color rgb 1] }
  }
}

#declare Tower = cylinder { <0,0,0>, <0,.2,0>, .1 pigment { color rgb .5 } translate
<0,2,0> }

#declare H = 0.15;
#declare W = 0.15;

object { Tower translate <-1.94, 0,-0.44> }
Wall(<-1.94, 2.0,-0.44>, <-2.05, 2.0,-0.20>,W, H, 0)
object { Tower translate <-2.05, 0,-0.20> }
Wall(<-2.05, 2.0,-0.20>, <-1.65, 2.0, 0.70>,W, H, 0)
object { Tower translate <-1.65, 0, 0.70> }
Wall(<-1.65, 2.0, 0.70>, <-1.72, 2.0, 1.13>,W, H, 0)
object { Tower translate <-1.72, 0, 1.13> }
Wall(<-1.72, 2.0, 1.13>, <-1.10, 2.0, 1.37>,W, H, 0)
object { Tower translate <-1.10, 0, 1.37> }
Wall(<-1.10, 2.0, 1.37>, <-0.20, 2.0, 1.38>,W, H, 0)
object { Tower translate <-0.20, 0, 1.38> }
Wall(<-0.20, 2.0, 1.38>, < 0.30, 2.0, 1.20>,W, H, 0)
object { Tower translate < 0.30, 0, 1.20> }
Wall(< 0.30, 2.0, 1.20>, < 0.92, 2.0, 1.41>,W, H, 0)
object { Tower translate < 0.92, 0, 1.41> }
Wall(< 0.92, 2.0, 1.41>, < 1.32, 2.0, 1.25>,W, H, 0)
object { Tower translate < 1.32, 0, 1.25> }
Wall(< 1.32, 2.0, 1.25>, < 1.90, 2.0, 1.35>,W, H, 0)
object { Tower translate < 1.90, 0, 1.35> }
Wall(< 1.90, 2.0, 1.35>, < 1.95, 2.0, 0.68>,W, H, 0)
object { Tower translate < 1.95, 0, 0.68> }
Wall(< 1.95, 2.0, 0.68>, < 1.32, 2.0, 0.10>,W, H, 0)
object { Tower translate < 1.32, 0, 0.10> }
Wall(< 1.32, 2.0, 0.10>, < 0.90, 2.0, 0.15>,W, H, 0)
object { Tower translate < 0.90, 0, 0.15> }
Wall(< 0.90, 2.0, 0.15>, < 0.21, 2.0,-0.50>,W, H, 0)
object { Tower translate < 0.21, 0,-0.50> }
Wall(< 0.21, 2.0,-0.50>, <-0.15, 2.0,-0.55>,W, H, 0)
object { Tower translate <-0.15, 0,-0.55> }
Wall(<-0.15, 2.0,-0.55>, <-0.55, 2.0,-1.09>,W, H, 0)
object { Tower translate <-0.55, 0,-1.09> }
Wall(<-0.55, 2.0,-1.09>, <-0.85, 2.0,-1.00>,W, H, 0)
object { Tower translate <-0.85, 0,-1.00> }
Wall(<-0.85, 2.0,-1.00>, <-1.10, 2.0,-0.45>,W, H, 0)
object { Tower translate <-1.10, 0,-0.45> }
Wall(<-1.10, 2.0,-0.45>, <-1.45, 2.0,-0.30>,W, H, 0)
object { Tower translate <-1.45, 0,-0.30> }
Wall(<-1.45, 2.0,-0.30>, <-1.94, 2.0,-0.44>,W, H, 0)


-- 
Rich Allen
(Remove SPAM from my address to reply by e-mail)


Post a reply to this message

From: Warp
Subject: Re: looking for a box macro
Date: 4 Jun 2001 05:29:06
Message: <3b1b54e2@news.povray.org>
Rich <SrP### [at] ricoswebcom> wrote:
: Unfortunately, most of the boxes are rotated incorrectly along their length,
: depending on the angle between the points I'm assuming.

  That's why there's a 'Rotation' parameter there.

  And I don't know how the matrix transformations rotate the object. You'll
have to ask John VanSickle about that (I got the orientation transformations
from his matrix page).

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Rich
Subject: Re: looking for a box macro
Date: 4 Jun 2001 22:39:15
Message: <Xns90B6D2226C17Espammindspringcom@204.213.191.228>
Warp <war### [at] tagpovrayorg> wrote in <3b1b54e2@news.povray.org>:

> Rich <SrP### [at] ricoswebcom> wrote:
>: Unfortunately, most of the boxes are rotated incorrectly along their
>: length, depending on the angle between the points I'm assuming.
> 
>   That's why there's a 'Rotation' parameter there.

  Hmm, I guess I can keep guessing/rendering until I get the correct 
rotation for each wall.  Maybe I'll bite the bullet and try to figure out 
the macro code instead.  <smile>  Thanks again for the help!

-- 
Rich Allen
(Remove SPAM from my address to reply by e-mail)


Post a reply to this message

From: Duncan Gray
Subject: Re: looking for a box macro
Date: 8 Jun 2001 16:17:04
Message: <3b2132c0@news.povray.org>
Rich wrote:
> Unfortunately, most of the boxes are rotated incorrectly along their
length,
> depending on the angle between the points I'm assuming.  Here is a sample
> scene showing what I mean:

Here you go - try this for size:

#macro Wall(Point1,Point2,Width,Height,np)
  #local direct=(Point2-Point1);
  #local y_rot=180*atan2(direct.x,direct.z)/pi;
  #local direct=vrotate(direct,-<0,y_rot,0>);
  #local x_rot=-180*atan2(direct.y,direct.z)/pi;
  #local direct=vrotate(direct,-<x_rot,0,0>);
  box { <-Width/2,0,0>,<Width/2,Height,direct.z>
        rotate <x_rot,y_rot,0>
        pigment { color rgb .5 }
        translate Point1
    }
#end


The 'np' parameter is not used - this is just there so you can directly drop
this routine into the sample code you provided. I have added the pigment
statement here, again to match how you have modified Warp's code.

Sorry - I'm no good with vectors, cross and dot products, etc. I fall back
on basic pythag and do it the not-so-elegant way.

Hope this helps.

--
Duncan Gray
(warning: may contain traces of nut)


Post a reply to this message

From: Rich
Subject: Re: looking for a box macro
Date: 8 Jun 2001 20:34:53
Message: <Xns90BABD0D66585spammindspringcom@204.213.191.228>
"Duncan Gray" <dun### [at] eclipsecouk> wrote in
<3b2132c0@news.povray.org>: 

> Here you go - try this for size:
> 
<snip>
> 
> Hope this helps.

  Are you kidding me?  This is awesome help!  Thank you, thank you, thank 
you!  With your mods to the macro I can spiff up the plain old box with 
some CSG and feel fairly confident I won't mess it up.  I can actually 
understand how it works (mostly :) and can play with it further from here.
  Many thanks, again!  

-- 
Rich Allen
(Remove SPAM from my address to reply by e-mail)


Post a reply to this message

From: Duncan Gray
Subject: Re: looking for a box macro
Date: 9 Jun 2001 18:35:02
Message: <3b22a496@news.povray.org>
Rich wrote:
>   Many thanks, again!

glad to be of service  :)

--
Duncan Gray
(warning: may contain traces of nut)


Post a reply to this message

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