POV-Ray : Newsgroups : povray.general : OBB to AABB question Server Time
28 Mar 2024 07:41:50 EDT (-0400)
  OBB to AABB question (Message 1 to 3 of 3)  
From: jr
Subject: OBB to AABB question
Date: 23 Feb 2019 08:40:00
Message: <web.5c714cdab0e359c4bcd610c90@news.povray.org>
hi,

as a part of a process I calculate two random-ish 3d points which are the base
and cap centres of a cylinder.  I now want to transform the cylinder such that
the base is at origin and the Y axis is the centre axis.  after adding some
points relative to the centre axis, I need to transform the cylinder back to its
original position.

as the cylinder is "oriented", I cannot fathom how/where to get "my angles" wrt
the POV-Ray "world" axes.  can someone please take me through a worked example,
or point out a good www resource?  tia.


regards, jr.


Post a reply to this message

From: Alain
Subject: Re: OBB to AABB question
Date: 23 Feb 2019 12:37:44
Message: <5c7184e8$1@news.povray.org>
Le 19-02-23 à 08:38, jr a écrit :
> hi,
> 
> as a part of a process I calculate two random-ish 3d points which are the base
> and cap centres of a cylinder.  I now want to transform the cylinder such that
> the base is at origin and the Y axis is the centre axis.  after adding some
> points relative to the centre axis, I need to transform the cylinder back to its
> original position.
> 
> as the cylinder is "oriented", I cannot fathom how/where to get "my angles" wrt
> the POV-Ray "world" axes.  can someone please take me through a worked example,
> or point out a good www resource?  tia.
> 
> 
> regards, jr.
> 
> 

If you want an end of the cylinder to get moved to the origin, a simple 
translate by the inverse of it's coordinate will do the trick :
You must set Range1, Range2, Offset1 and Offset2 to your needs.

#include "transforms.inc"
#declare R=seed(34);
...
#declare End1= <rand(R), rand(R), rand(R)>*Range1+Offset1
#declare End2= <rand(R), rand(R), rand(R)>*Range2+Offset2

#declare MyCylinder = cylinder{End1, End2, Radius}

//Move End1 to the origin :
#declare CylinderAtOrigin = object{MyCylinder translate -End1}

*//Reorient it to the Y axis :
#declare WorkCylinder = object{CylinderAtOrigin 
transform{Reorient_Trans(End2, y)}}

Do whatever else you want here...

//Restore the original orientation :
#declare CylinderAtOrigin = object{WorkCylinder 
transform{Reorient_Trans(y, End2)}}

//Bring back to the original location :
#declare MyCylinder = object{CylinderAtOrigin translate End1}

It can be shortened by combining the translations and rotations :

#declare WorkCylinder = object{MyCylinder translate -End1 
transform{Reorient_Trans(End2, y)}}

Do whatever else you want here...

// Restore original orientation and location :
#declare MyCylinder = object{WorkCylinder transform{Reorient_Trans(y, 
End2)} translate End1}



Alain


Post a reply to this message

From: jr
Subject: Re: OBB to AABB question
Date: 23 Feb 2019 14:30:00
Message: <web.5c719e0821c80ddbbcd610c90@news.povray.org>
hi,

Alain <kua### [at] videotronca> wrote:

a perfect-for-my-needs reply, thank you.

(looking at 'transforms.inc' had not even occurred to me.  </sigh>)


regards, jr.


Post a reply to this message

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