POV-Ray : Newsgroups : povray.newusers : object parameters Server Time
20 Jun 2024 17:42:52 EDT (-0400)
  object parameters (Message 1 to 10 of 10)  
From: seNex
Subject: object parameters
Date: 13 Feb 2023 11:30:00
Message: <web.63ea642218d647779b54cfa5c411274@news.povray.org>
is there a way to get the parameter of an object after its declaration? For
example if I create a sphere named mysphere with center <x,y,z> and radius 1,
can I use a
function to write these to new variables? Like:


#declare mysphere=sphere{<x,y,z>,1};

#declare sphere_center=centerfunction(mysphere);
#declare sphere_radius=radiusfunktion(mysphere);


Post a reply to this message

From: Cousin Ricky
Subject: Re: object parameters
Date: 13 Feb 2023 12:16:40
Message: <63ea7078$1@news.povray.org>
On 2023-02-13 12:26(-4), seNex wrote:
> is there a way to get the parameter of an object after its declaration? For
> example if I create a sphere named mysphere with center <x,y,z> and radius 1,
> can I use a
> function to write these to new variables? Like:
> 
> 
> #declare mysphere=sphere{<x,y,z>,1};
> 
> #declare sphere_center=centerfunction(mysphere);
> #declare sphere_radius=radiusfunktion(mysphere);

There are no direct functions of this kind in POV-Ray, but you can
estimate the parameters by taking the bounding extents of the object:

#declare mysphere_center =
  (max_extent (mysphere) + min_extent (mysphere)) / 2;
#declare sphere_radius =
  (max_extent (mysphere).x - min_extent (mysphere).x) / 2;

Be aware that this is not perfectly reliable.  The functions
max_extent() and min_extent() are only estimates, and tend to grow
larger than the objects as transformations and CSG operations are
applied to the object.  But for a simple primitive such as a sphere, it
should work.


Post a reply to this message

From: Alain Martel
Subject: Re: object parameters
Date: 13 Feb 2023 12:23:39
Message: <63ea721b$1@news.povray.org>
Le 2023-02-13 à 11:26, seNex a écrit :
> is there a way to get the parameter of an object after its declaration? For
> example if I create a sphere named mysphere with center <x,y,z> and radius 1,
> can I use a
> function to write these to new variables? Like:
> 
> 
> #declare mysphere=sphere{<x,y,z>,1};
> 
> #declare sphere_center=centerfunction(mysphere);
> #declare sphere_radius=radiusfunktion(mysphere);
> 
> 

There are no such function. Those values are never visible from the SDL 
perspective. The recommended thing to do is to declare the centre and 
radius then to use those declared value when you #declare your object :

#declare Sphere_centre= Some_location;
#declare Sphere_radius= Some_Radius;
#declare Mysphere=sphere{Sphere_centre, Sphere_radius}


Post a reply to this message

From: seNex
Subject: Re: object parameters
Date: 15 Feb 2023 05:35:00
Message: <web.63ecb45bdae7e3799b54cfa5c411274@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:
> On 2023-02-13 12:26(-4), seNex wrote:
> > is there a way to get the parameter of an object after its declaration? For
> > example if I create a sphere named mysphere with center <x,y,z> and radius 1,
> > can I use a
> > function to write these to new variables? Like:
> >
> >
> > #declare mysphere=sphere{<x,y,z>,1};
> >
> > #declare sphere_center=centerfunction(mysphere);
> > #declare sphere_radius=radiusfunktion(mysphere);
>
> There are no direct functions of this kind in POV-Ray, but you can
> estimate the parameters by taking the bounding extents of the object:
>
> #declare mysphere_center =
>   (max_extent (mysphere) + min_extent (mysphere)) / 2;
> #declare sphere_radius =
>   (max_extent (mysphere).x - min_extent (mysphere).x) / 2;
>
> Be aware that this is not perfectly reliable.  The functions
> max_extent() and min_extent() are only estimates, and tend to grow
> larger than the objects as transformations and CSG operations are
> applied to the object.  But for a simple primitive such as a sphere, it
> should work.

Thanks for the quick reply. I had tried this myself before but thought there
ought to be a more elegant solution.


Post a reply to this message

From: seNex
Subject: Re: object parameters
Date: 15 Feb 2023 05:40:00
Message: <web.63ecb61edae7e3799b54cfa5c411274@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:

> > is there a way to get the parameter of an object after its declaration? For
> > example if I create a sphere named mysphere with center <x,y,z> and radius 1,
> > can I use a
> > function to write these to new variables? Like:
> >
> >
> > #declare mysphere=sphere{<x,y,z>,1};
> >
> > #declare sphere_center=centerfunction(mysphere);
> > #declare sphere_radius=radiusfunktion(mysphere);
> >
> >
>
> There are no such function. Those values are never visible from the SDL
> perspective. The recommended thing to do is to declare the centre and
> radius then to use those declared value when you #declare your object :
>
> #declare Sphere_centre= Some_location;
> #declare Sphere_radius= Some_Radius;
> #declare Mysphere=sphere{Sphere_centre, Sphere_radius}

thanks for the quick reply. The underlying problem is, I wanted to track the
center of the sphere after applying transformations to it. It seems to me from
the documentation, that there is no way to apply transformations to the vector,
but only to objects.


Post a reply to this message

From: William F Pokorny
Subject: Re: object parameters
Date: 15 Feb 2023 07:20:40
Message: <63ecce18$1@news.povray.org>
On 2/15/23 05:38, seNex wrote:
> thanks for the quick reply. The underlying problem is, I wanted to track the
> center of the sphere after applying transformations to it. It seems to me from
> the documentation, that there is no way to apply transformations to the vector,
> but only to objects.

You can do something like:

#version 3.8;
global_settings { assumed_gamma 1 }

#declare Vec00 = <0,0,0>;
#declare Xfrm00 = transform {
     translate <0.5,0.0,0.0>
     rotate z*30.0
}
#declare FnXfrm00 = function { transform {Xfrm00} }

// You might need to use 'inverse', if result is to be used in a
// isosurface function , for example.
// #declare FnXfrm00 = function { transform {Xfrm00 inverse} }

#debug concat("Vec00.x --> ",str(Vec00.x,0,-1)," transformed to --> ",
     str(FnXfrm00(Vec00.x,Vec00.y,Vec00.z).x,0,-1),".\n")
#debug concat("Vec00.y --> ",str(Vec00.y,0,-1)," transformed to --> ",
     str(FnXfrm00(Vec00.x,Vec00.y,Vec00.z).y,0,-1),".\n")
#debug concat("Vec00.z --> ",str(Vec00.z,0,-1)," transformed to --> ",
     str(FnXfrm00(Vec00.x,Vec00.y,Vec00.z).z,0,-1),".\n")

#declare Vec00_Xfrmed =
<FnXfrm00(Vec00.x,Vec00.y,Vec00.z).x,
FnXfrm00(Vec00.x,Vec00.y,Vec00.z).y,
FnXfrm00(Vec00.x,Vec00.y,Vec00.z).z>;

#debug concat("\nXfrmed vector <",
     vstr(3,Vec00_Xfrmed, ",", 0, 3), ">\n\n")

#error "\nStopping by #error after parse"

---

If you want to capture a more complete set of 'coordinate modifiers', 
for example, turbulence or warps along with transforms, you are stuck 
in any official POV-Ray release as far as I know.

The povr fork introduced a vector function called pattern_modifiers 
which captures a complete sequence of positional modifiers as a function 
which then can be used as FnXfrm00 is up top.

#declare FnXfrm00 = function {
     pattern_modifiers { Pigment00 }
}

However, at best, such functionality wouldn't show up until a v4.0 
official release.

Bill P.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: object parameters
Date: 15 Feb 2023 08:00:00
Message: <web.63ecd6f4dae7e3794e68426589db30a9@news.povray.org>
"seNex" <nomail@nomail> wrote:
>...
> The underlying problem is, I wanted to track the
> center of the sphere after applying transformations to it. It seems to me from
> the documentation, that there is no way to apply transformations to the vector,
> but only to objects.

You can use vtransform() which is documented here:

https://www.povray.org/documentation/view/3.7.0/488/

- or VectorTransform() which can be found here:

https://github.com/t-o-k/Useful-POV-Ray-macros

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: William F Pokorny
Subject: Re: object parameters
Date: 15 Feb 2023 10:53:05
Message: <63ecffe1$1@news.povray.org>
On 2/15/23 07:20, William F Pokorny wrote:
> #declare Vec00_Xfrmed =
> <FnXfrm00(Vec00.x,Vec00.y,Vec00.z).x,
> FnXfrm00(Vec00.x,Vec00.y,Vec00.z).y,
> FnXfrm00(Vec00.x,Vec00.y,Vec00.z).z>;

The light went on in my head a minute ago that I'd coded the part above 
without thinking. It can be just:

#declare Vec00_Xfrmed = FnXfrm00(Vec00.x,Vec00.y,Vec00.z);

---

That said, Tor Olav's suggestions are the cleaner method from the users 
perspective. Internally those macros use the function based code too.

The best approach for performance depends on what you are doing. Using a 
single transform against a lot of vectors will favor raw coding approach 
where the transform function can be parsed, compiled and defined once. 
If many transforms against few vectors, the macro's are the way to go.

Bill P.


Post a reply to this message

From: Bald Eagle
Subject: Re: object parameters
Date: 15 Feb 2023 14:40:00
Message: <web.63ed34f2dae7e3791f9dae3025979125@news.povray.org>
"seNex" <nomail@nomail> wrote:

> thanks for the quick reply. The underlying problem is, I wanted to track the
> center of the sphere after applying transformations to it. It seems to me from
> the documentation, that there is no way to apply transformations to the vector,
> but only to objects.

Well, that's not completely true.
I have asked this question before, and here's what you can do:

#include "transforms.inc"
// Translate a "point"
#declare Translate = transform { translate { <x, y, z> } }
#declare NewPoint = vtransform (OldPoint, Translate);

And you can do that with any transformation.

Now, that's not very convenient when you want to just have the information
"attached" to the sphere, but I think I've found a way to do that.   POV-Ray
does not complain when you create a box {} with the two diagonal corners being
the same vector.

So, you can probably just write a little macro that applies whatever
transformations to your sphere, but also applies the transformations to the
zero-dimensional "box".  But you do it in a way where you don't just transform
the box, you redefine the old box as the box with the transform applied.

like:  #declare Box = vtransform (Box, Translate);

Then you can use min_extent and max_extent to get the coordinates of the point.
It's convoluted, but it gets the job done.

- BE



snippets:

#declare Box = box {1, 1}
#declare Min = min_extent (Box);
#declare Max = max_extent (Box);

// {Be sure to include debug.inc file!}

#debug concat( "Min = ", vstr(3, Min, ", ", 3, 0), " \n")
#debug concat( "Max = ", vstr(3, Max, ", ", 3, 0), " \n")


Post a reply to this message

From: seNex
Subject: Re: object parameters
Date: 17 Feb 2023 08:30:00
Message: <web.63ef8118dae7e3799b54cfa5c411274@news.povray.org>
thanks alot!! The latest answers solved my problem completely! :D


Post a reply to this message

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