POV-Ray : Newsgroups : povray.general : Vector identifiers/axis values in a float function Server Time
24 Dec 2024 21:02:58 EST (-0500)
  Vector identifiers/axis values in a float function (Message 1 to 10 of 10)  
From: INVALID ADDRESS
Subject: Vector identifiers/axis values in a float function
Date: 3 Dec 2016 06:47:30
Message: <27201814.502457693.399803.gdsHYPHENentropyAThotmaolDOTcom@news.povray.org>
Hello,

In a macro when I have a parameter of type vector and pass its value as
such, I get an error:

abs(x - Position.x)

But if I do this it works:

#local positionX = Position.x;
abs(x - positionX)

Why is this, and is there a way to do what I want to do?

While abs is not a vector function the component part x is a float, right?
So it seems like it should take it.

It seems like there is either a parsing oversight, or that the axis values
are not internally scalars, and as thus the local variable results in a
cast or something that allows it to work.

In the case of my macro the way I want to do this is cleaner than the other
way in my opinion, as I an trying to cut down on the number of parameters
in my macro and keep the local variables to a minimum.

Thanks,
Ian


Post a reply to this message

From: William F Pokorny
Subject: Re: Vector identifiers/axis values in a float function
Date: 3 Dec 2016 09:51:30
Message: <5842dbf2$1@news.povray.org>
On 12/03/2016 06:47 AM, [GDS|Entropy] wrote:
> Hello,
>
> In a macro when I have a parameter of type vector and pass its value as
> such, I get an error:
>
> abs(x - Position.x)
>
> But if I do this it works:
>
> #local positionX = Position.x;
> abs(x - positionX)
>
> Why is this, and is there a way to do what I want to do?
>
> While abs is not a vector function the component part x is a float, right?
> So it seems like it should take it.
>
> It seems like there is either a parsing oversight, or that the axis values
> are not internally scalars, and as thus the local variable results in a
> cast or something that allows it to work.
>
> In the case of my macro the way I want to do this is cleaner than the other
> way in my opinion, as I an trying to cut down on the number of parameters
> in my macro and keep the local variables to a minimum.
>
> Thanks,
> Ian
>
I'm likely not following the "works vs not works" part of the story, but 
I think it the case 'x' is really shorthand for <1,0,0> inside POV-Ray 
and so abs() is going to see a vector expression for what you've written 
and not a float. This should be true in both cases you've outlined, but 
maybe I'm not seeing what makes this not so.

In other words 'x' is part of the SDL language denoting the x unit vector.

Use instead perhaps MyX and set it to 1 - or just use 1 and I think 
you'll be OK.

Bill P.


Post a reply to this message

From: clipka
Subject: Re: Vector identifiers/axis values in a float function
Date: 3 Dec 2016 10:33:31
Message: <5842e5cb@news.povray.org>
Am 03.12.2016 um 12:47 schrieb [GDS|Entropy]:

> In a macro when I have a parameter of type vector and pass its value as
> such, I get an error:
> 
> abs(x - Position.x)
> 
> But if I do this it works:
> 
> #local positionX = Position.x;
> abs(x - positionX)

I very much doubt that the latter works.

As William already pointed out, the problem isn't so much the use of
`Position`, or even `Position.x`, but the very first term of the
expression inside `abs()`: The lone `x`.

When standing on its own (as opposed to `Something.x`) outside of a
function definition, `x` is a constant evaluating to `<1,0,0>`. Thus,
the expression

    abs(x - Position.x)

is equivalent to

    abs(<1,0,0> - Position.x)

which, thanks to scalar-to-vector promotion, is in turn equivalent to

    abs(<1,0,0> - <Position.x,0,0>)

which in turn is equivalent to

    abs(<1-Position.x,0,0>)

The location given for the error message may be misleading, but POV-Ray
does not know that the expression inside the `abs()` will evaluate to a
vector until it has indeed completely parsed the expression.


Post a reply to this message

From: omniverse
Subject: Re: Vector identifiers/axis values in a float function
Date: 3 Dec 2016 11:55:00
Message: <web.5842f7eeb14df8439c5d6c810@news.povray.org>
Perhaps a curiosity of how the dot operator actually works, maybe x.x will be
possible?
Trying that here, this seemed to bypass the problem with abs() seeing a "vector
or color expression".
I sure don't know the reasoning myself, just occurred to me it might remove the
vectorness in a way it does a whole vector.


Post a reply to this message

From: clipka
Subject: Re: Vector identifiers/axis values in a float function
Date: 3 Dec 2016 12:23:16
Message: <5842ff84$1@news.povray.org>
Am 03.12.2016 um 17:50 schrieb omniverse:
> Perhaps a curiosity of how the dot operator actually works, maybe x.x will be
> possible?
> Trying that here, this seemed to bypass the problem with abs() seeing a "vector
> or color expression".
> I sure don't know the reasoning myself, just occurred to me it might remove the
> vectorness in a way it does a whole vector.

Yes, `x.x` is a valid expression -- but since it evaluates to the
constant `1`, there are easier ways to write it ;)

With that in mind, I have a hunch that `x.x` isn't what Ian intended...


Post a reply to this message

From: omniverse
Subject: Re: Vector identifiers/axis values in a float function
Date: 3 Dec 2016 13:55:00
Message: <web.584313ddb14df8439c5d6c810@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 03.12.2016 um 17:50 schrieb omniverse:
> > Perhaps a curiosity of how the dot operator actually works, maybe x.x will be
> > possible?
> > Trying that here, this seemed to bypass the problem with abs() seeing a "vector
> > or color expression".
>
> Yes, `x.x` is a valid expression -- but since it evaluates to the
> constant `1`, there are easier ways to write it ;)

Ah yes, well there ya go. And in my mind the x could be any integer or float, at
least when thinking about possibilities.  :)  I think too much, often wrongly.


Post a reply to this message

From: Leroy
Subject: Re: Vector identifiers/axis values in a float function
Date: 6 Dec 2016 13:35:01
Message: <web.58470473b14df8437b53a6a20@news.povray.org>
[GDS|Entropy] <gdsHYPHENentropyAThotmaolDOTcom> wrote:
> Hello,
>
> In a macro when I have a parameter of type vector and pass its value as
> such, I get an error:
>
> abs(x - Position.x)
>
> But if I do this it works:
>
> #local positionX = Position.x;
> abs(x - positionX)
>

This works:
#local P=<3,25,20>;
#local A=abs((x-P).x);
#debug concat("A =",str(A,0,0),"\n")


Post a reply to this message

From: INVALID ADDRESS
Subject: Re: Vector identifiers/axis values in a float function
Date: 10 Dec 2016 07:58:43
Message: <517205995.503063383.194364.gdsHYPHENentropyAThotmaolDOTcom@news.povray.org>
Leroy <whe### [at] gmailcom> wrote:
> [GDS|Entropy] <gdsHYPHENentropyAThotmaolDOTcom> wrote:
>> Hello,
>> 
>> In a macro when I have a parameter of type vector and pass its value as
>> such, I get an error:
>> 
>> abs(x - Position.x)
>> 
>> But if I do this it works:
>> 
>> #local positionX = Position.x;
>> abs(x - positionX)
>> 
> 
> This works:
> #local P=<3,25,20>;
> #local A=abs((x-P).x);
> #debug concat("A =",str(A,0,0),"\n")
> 

Unfortunately this will not function correctly for me as the same error
manifests, I guess based on what others have said it could be due to being
in a macro.

Oh well. :(

In


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Vector identifiers/axis values in a float function
Date: 10 Dec 2016 11:20:00
Message: <web.584c2a08b14df8437b4f57df0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 03.12.2016 um 12:47 schrieb [GDS|Entropy]:
>
> > In a macro when I have a parameter of type vector and pass its value as
> > such, I get an error:
> >
> > abs(x - Position.x)
> >
> > But if I do this it works:
> >
> > #local positionX = Position.x;
> > abs(x - positionX)
>
> I very much doubt that the latter works.
>
> As William already pointed out, the problem isn't so much the use of
> `Position`, or even `Position.x`, but the very first term of the
> expression inside `abs()`: The lone `x`.
>
> When standing on its own (as opposed to `Something.x`) outside of a
> function definition, `x` is a constant evaluating to `<1,0,0>`. Thus,
> the expression
>
>     abs(x - Position.x)
>
> is equivalent to
>
>     abs(<1,0,0> - Position.x)
>
> which, thanks to scalar-to-vector promotion, is in turn equivalent to
>
>     abs(<1,0,0> - <Position.x,0,0>)
>
> which in turn is equivalent to
>
>     abs(<1-Position.x,0,0>)

Clipka, I think you meant to write this:


which, thanks to scalar-to-vector promotion, is in turn equivalent to

     abs(<1,0,0> - <Position.x, Position.x, Position.x>)

which in turn is equivalent to:

     abs(<1 - Position.x, -Position.x, -Position.x>)


Ian, I suggest that you try this:

#declare Position = <9, 7, 5>;
#declare Result = x - Position.x;
#debug concat("\n\n<", vstr(3, Result, ", ", 0, -1), ">\n\n")
#error "To easier see the result"


Btw.: I wish POV-Ray had a "#stop" directive that didn't make so much fuss about
stopping. A directive that results in parsing only, without rendering, would be
great for code that is not written for the purpose of creating an image - which
I write a lot of.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: clipka
Subject: Re: Vector identifiers/axis values in a float function
Date: 10 Dec 2016 19:39:58
Message: <584ca05e$1@news.povray.org>
Am 10.12.2016 um 17:16 schrieb Tor Olav Kristensen:

>> When standing on its own (as opposed to `Something.x`) outside of a
>> function definition, `x` is a constant evaluating to `<1,0,0>`. Thus,
>> the expression
>>
>>     abs(x - Position.x)
>>
>> is equivalent to
>>
>>     abs(<1,0,0> - Position.x)
>>
>> which, thanks to scalar-to-vector promotion, is in turn equivalent to
>>
>>     abs(<1,0,0> - <Position.x,0,0>)
>>
>> which in turn is equivalent to
>>
>>     abs(<1-Position.x,0,0>)
> 
> Clipka, I think you meant to write this:
> 
> 
> which, thanks to scalar-to-vector promotion, is in turn equivalent to
> 
>      abs(<1,0,0> - <Position.x, Position.x, Position.x>)
> 
> which in turn is equivalent to:
> 
>      abs(<1 - Position.x, -Position.x, -Position.x>)

No, I did mean to write what I wrote -- though that doesn't make it any
better ;)

You are, of course, right.


> Btw.: I wish POV-Ray had a "#stop" directive that didn't make so much fuss about
> stopping. A directive that results in parsing only, without rendering, would be
> great for code that is not written for the purpose of creating an image - which
> I write a lot of.

Command-line options `-f -d` should do the trick.

(What I'm missing more is a generic means to merge the INI settings and
scene description into one single file, which would thus cover your
feature request. But I'm not sure yet how to tackle that. Maybe an
optional `#ini ... #end` block at the start of the file, which the
front-end could scan for and the parser could skip over.)


Post a reply to this message

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