POV-Ray : Newsgroups : povray.general : OBB to AABB question Server Time: 19 May 2019 10:20:18 GMT
 OBB to AABB question (Message 1 to 3 of 3)
 From: jr Subject: OBB to AABB question Date: 23 Feb 2019 13:40:00 Message:
```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.
```
 From: Alain Subject: Re: OBB to AABB question Date: 23 Feb 2019 17: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
```
 From: jr Subject: Re: OBB to AABB question Date: 23 Feb 2019 19:30:00 Message:
```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.
```