POV-Ray : Newsgroups : povray.newusers : Aligned box? Server Time
1 Nov 2024 11:16:50 EDT (-0400)
  Aligned box? (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: Tyler Eaves
Subject: Aligned box?
Date: 7 Sep 2005 14:25:15
Message: <op.swqv57j705glvk@localhost.localdomain>
I'm looking for some way to specify a box at an angle. The way I see it, a  
box could be specified by giving 2 points, which would be the center of  
two oppisite faces, and would define one dimesion, call it length, and  
then giving the length of the width and height. This would be roughly  
comprable to the way a cylinder is specified. I can't seem to think of any  
obvious way to do this (3d math is not a strength of mine...)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Post a reply to this message

From: Mike Williams
Subject: Re: Aligned box?
Date: 7 Sep 2005 14:58:16
Message: <gE4reDADhzHDFwbT@econym.demon.co.uk>
Wasn't it Tyler Eaves who wrote:
>I'm looking for some way to specify a box at an angle. The way I see it, a  
>box could be specified by giving 2 points, which would be the center of  
>two oppisite faces, and would define one dimesion, call it length, and  
>then giving the length of the width and height. This would be roughly  
>comprable to the way a cylinder is specified. I can't seem to think of any  
>obvious way to do this (3d math is not a strength of mine...)

The first thing that springs to mind is to write a macro like this:

#include "transforms.inc"
#macro aligned_box(P1, P2, H, W)
  #local L = abs(vlength(P2-P1));
  box {<0,-H/2,-W/2><L,H/2,W/2>
    transform {Reorient_Trans(x,P2-P1)}
    translate P1
  }
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tyler Eaves
Subject: Re: Aligned box?
Date: 7 Sep 2005 20:12:09
Message: <op.swrb8gcw05glvk@localhost.localdomain>
On Wed, 07 Sep 2005 14:58:11 -0400, Mike Williams  
<nos### [at] econymdemoncouk> wrote:

> Wasn't it Tyler Eaves who wrote:
>> I'm looking for some way to specify a box at an angle. The way I see  
>> it, a
>> box could be specified by giving 2 points, which would be the center of
>> two oppisite faces, and would define one dimesion, call it length, and
>> then giving the length of the width and height. This would be roughly
>> comprable to the way a cylinder is specified. I can't seem to think of  
>> any
>> obvious way to do this (3d math is not a strength of mine...)
>
> The first thing that springs to mind is to write a macro like this:
>
> #include "transforms.inc"
> #macro aligned_box(P1, P2, H, W)
>   #local L = abs(vlength(P2-P1));
>   box {<0,-H/2,-W/2><L,H/2,W/2>
>     transform {Reorient_Trans(x,P2-P1)}
>     translate P1
>   }
> #end
>

That comes VERY close. Actually, it works as I requested, although missing  
an implied criteria. I didn't specify it, but I need the box to maintain a  
vertical orientation, whereas your macro induces a rotation around the  
P1-P2 axis. I'm guessing this is an artifact of the Reorient_Trans



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Post a reply to this message

From: gonzo
Subject: Re: Aligned box?
Date: 8 Sep 2005 00:36:14
Message: <431fbfbe@news.povray.org>
Tyler Eaves wrote:
> On Wed, 07 Sep 2005 14:58:11 -0400, Mike Williams  
> <nos### [at] econymdemoncouk> wrote:

>> #include "transforms.inc"
>> #macro aligned_box(P1, P2, H, W)
>>   #local L = abs(vlength(P2-P1));
>>   box {<0,-H/2,-W/2><L,H/2,W/2>
>>     transform {Reorient_Trans(x,P2-P1)}
>>     translate P1
>>   }
>> #end
>>
> 
> That comes VERY close. Actually, it works as I requested, although 
> missing  an implied criteria. I didn't specify it, but I need the box to 
> maintain a  vertical orientation, whereas your macro induces a rotation 
> around the  P1-P2 axis. I'm guessing this is an artifact of the 
> Reorient_Trans

I'm assuming you're generating P1 & P2 somewhere else?  I believe you 
either have to ensure both y points are the same before passing them to 
the macro or else remove them in the macro.  Does this work?

#include "transforms.inc"
#macro aligned_box(P1, P2, H, W)
	#local L = abs(vlength(P2-P1));
	#local FP1 = <P1.x, 0, P1.z>;
	#local FP2 = <P2.x, 0, P2.z>;
	box {<0,-H/2,-W/2><L,H/2,W/2>
		transform {Reorient_Trans(x,FP2-FP1)}
		translate P1
	}




RG


Post a reply to this message

From: gonzo
Subject: Re: Aligned box?
Date: 8 Sep 2005 00:41:39
Message: <431fc103@news.povray.org>
Mike Williams wrote:
> Wasn't it Tyler Eaves who wrote:
> 
>>I'm looking for some way to specify a box at an angle. The way I see it, a  
>>box could be specified by giving 2 points, which would be the center of  
>>two oppisite faces, and would define one dimesion, call it length, and  
>>then giving the length of the width and height. This would be roughly  
>>comprable to the way a cylinder is specified. I can't seem to think of any  
>>obvious way to do this (3d math is not a strength of mine...)
> 
> 
> The first thing that springs to mind is to write a macro like this:
> 
> #include "transforms.inc"
> #macro aligned_box(P1, P2, H, W)
>   #local L = abs(vlength(P2-P1));
>   box {<0,-H/2,-W/2><L,H/2,W/2>
>     transform {Reorient_Trans(x,P2-P1)}
>     translate P1
>   }
> #end
> 


Hey cool!  Thanks Mike, I was just trying to figure out how to make a 
box that acted like a cylinder!

RG  -  I can't count the times I've had a question to ask here that I 
never asked because someone had already posted the answer


Post a reply to this message

From: Mike Williams
Subject: Re: Aligned box?
Date: 8 Sep 2005 02:11:07
Message: <oLM2cJATW9HDFwbz@econym.demon.co.uk>
Wasn't it Tyler Eaves who wrote:
>On Wed, 07 Sep 2005 14:58:11 -0400, Mike Williams  
><nos### [at] econymdemoncouk> wrote:
>
>> Wasn't it Tyler Eaves who wrote:
>>> I'm looking for some way to specify a box at an angle. The way I see  
>>> it, a
>>> box could be specified by giving 2 points, which would be the center of
>>> two oppisite faces, and would define one dimesion, call it length, and
>>> then giving the length of the width and height. This would be roughly
>>> comprable to the way a cylinder is specified. I can't seem to think of  
>>> any
>>> obvious way to do this (3d math is not a strength of mine...)
>>
>> The first thing that springs to mind is to write a macro like this:
>>
>> #include "transforms.inc"
>> #macro aligned_box(P1, P2, H, W)
>>   #local L = abs(vlength(P2-P1));
>>   box {<0,-H/2,-W/2><L,H/2,W/2>
>>     transform {Reorient_Trans(x,P2-P1)}
>>     translate P1
>>   }
>> #end
>>
>
>That comes VERY close. Actually, it works as I requested, although missing  
>an implied criteria. I didn't specify it, but I need the box to maintain a  
>vertical orientation, whereas your macro induces a rotation around the  
>P1-P2 axis. I'm guessing this is an artifact of the Reorient_Trans

Point_At_Trans seems to produce boxes that are vertically aligned more
of the time, but I can't predict which of the directions is going to be
the height and which will be the width

#include "transforms.inc"
#macro aligned_box(P1, P2, H, W)
  #local L = abs(vlength(P2-P1));
  box {<-W/2,0,-H/2><W/2,L,H/2>
    transform {Point_At_Trans(P2-P1)}
    translate P1
  }
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Slime
Subject: Re: Aligned box?
Date: 8 Sep 2005 03:01:46
Message: <431fe1da$1@news.povray.org>
> That comes VERY close. Actually, it works as I requested, although missing
> an implied criteria. I didn't specify it, but I need the box to maintain a
> vertical orientation, whereas your macro induces a rotation around the
> P1-P2 axis. I'm guessing this is an artifact of the Reorient_Trans

Replace Reorient_Trans with this macro and it should work (untested code,
let me know if it doesn't):

// maps the x axis to vec while keeping "sky" as up,
// doesn't work if vec is parallel to sky
#macro Reorient_Trans_Sky(vec, sky)
    #local mapxto = vec;
    #local mapzto = vnormalize(vcross(sky, vec));
    #local mapyto = vcross(mapxto, mapzto);
    matrix <
        mapxto.x, mapxto.y, mapxto.z,
        mapyto.x, mapyto.y, mapyto.z,
        mapzto.x, mapzto.y, mapzto.z,
        0,0,0
    >
#end

Use it like Reorient_Trans_Sky(P2 - P1, y)

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Mike Williams
Subject: Re: Aligned box?
Date: 8 Sep 2005 05:22:21
Message: <wpBQEiAlE$HDFw6g@econym.demon.co.uk>
Wasn't it Slime who wrote:
>> That comes VERY close. Actually, it works as I requested, although missing
>> an implied criteria. I didn't specify it, but I need the box to maintain a
>> vertical orientation, whereas your macro induces a rotation around the
>> P1-P2 axis. I'm guessing this is an artifact of the Reorient_Trans
>
>Replace Reorient_Trans with this macro and it should work (untested code,
>let me know if it doesn't):
>
>// maps the x axis to vec while keeping "sky" as up,
>// doesn't work if vec is parallel to sky
>#macro Reorient_Trans_Sky(vec, sky)
>    #local mapxto = vec;
>    #local mapzto = vnormalize(vcross(sky, vec));
>    #local mapyto = vcross(mapxto, mapzto);
>    matrix <
>        mapxto.x, mapxto.y, mapxto.z,
>        mapyto.x, mapyto.y, mapyto.z,
>        mapzto.x, mapzto.y, mapzto.z,
>        0,0,0
>    >
>#end
>
>Use it like Reorient_Trans_Sky(P2 - P1, y)

A quick test reveals that "sky" is a reserved word, and the mapxto and
mapyto need to be vnormalized. So:

#macro Reorient_Trans_Sky(vec, Sky)
    #local mapxto = vnormalize(vec);
    #local mapzto = vnormalize(vcross(Sky, vec));
    #local mapyto = vnormalize(vcross(mapxto, mapzto));
    matrix <
        mapxto.x, mapxto.y, mapxto.z,
        mapyto.x, mapyto.y, mapyto.z,
        mapzto.x, mapzto.y, mapzto.z,
        0,0,0
    >
#end

#macro aligned_box(P1, P2, H, W)
  #local L = abs(vlength(P2-P1));
  box {<0,-H/2,-W/2><L,H/2,W/2>
    transform {Reorient_Trans_Sky(P2-P1,y)}
    translate P1
  }
#end

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tyler Eaves
Subject: Re: Aligned box?
Date: 8 Sep 2005 08:54:38
Message: <op.swsbjdax05glvk@localhost.localdomain>
On Thu, 08 Sep 2005 04:07:01 -0400, Mike Williams  
<nos### [at] econymdemoncouk> wrote:

> #macro Reorient_Trans_Sky(vec, Sky)
>     #local mapxto = vnormalize(vec);
>     #local mapzto = vnormalize(vcross(Sky, vec));
>     #local mapyto = vnormalize(vcross(mapxto, mapzto));
>     matrix <
>         mapxto.x, mapxto.y, mapxto.z,
>         mapyto.x, mapyto.y, mapyto.z,
>         mapzto.x, mapzto.y, mapzto.z,
>         0,0,0
>     >
> #end
> #macro aligned_box(P1, P2, H, W)
>   #local L = abs(vlength(P2-P1));
>   box {<0,-H/2,-W/2><L,H/2,W/2>
>     transform {Reorient_Trans_Sky(P2-P1,y)}
>     translate P1
>   }
> #end

Works great! This is insanely useful.


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Post a reply to this message

From: Tyler Eaves
Subject: Re: Aligned box?
Date: 8 Sep 2005 15:30:36
Message: <op.swstvcni05glvk@localhost.localdomain>
On Thu, 08 Sep 2005 00:40:14 -0400, gonzo <rgo### [at] lansetcom> wrote:

> Hey cool!  Thanks Mike, I was just trying to figure out how to make a  
> box that acted like a cylinder!
>
> RG  -  I can't count the times I've had a question to ask here that I  
> never asked because someone had already posted the answer
>

It's such a (to me) obvious thing that I'm surprised there isn't built in  
support for it. It's worth pointing out that the code as posted by Mike  
isn't quite perfect, but the code he posted later in reply to Slime *is*.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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