POV-Ray : Newsgroups : povray.general : condition parsed as vector Server Time
8 Aug 2024 08:14:47 EDT (-0400)
  condition parsed as vector (Message 1 to 10 of 10)  
From: KalleK
Subject: condition parsed as vector
Date: 15 Feb 2001 14:44:24
Message: <3a8c3198$1@news.povray.org>
Hi all Povers!
This is one of those "is it a bug?"-thingie.
I want to compare two vectors for a condition.
 #local V0 = x;
 #local Thing = ((V0=y):Foo?Bar);
This gives me an error : "Conditional must evaluate to a float."

And it's not done with #local Thing = Bar; :-)

Or another example for this thing is:
  #local T0 = x;
  #local T1 = 1;
  #local T1 = (T0=y);
This driggers the error : "Attempted to redifine float identifier as vector
identifier." but a
conditions should be represented as a boolean/float.

Do I have to compare every component seperated? Or what's the error?
Any solutions?

Thanx in advance!

cukk


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: condition parsed as vector
Date: 15 Feb 2001 15:26:47
Message: <3a8c3b87$1@news.povray.org>
In article <3a8c3198$1@news.povray.org> , "KalleK" <kal### [at] gmxde> 
wrote:

> Do I have to compare every component seperated?

Yes, you do.  There is no general way to compare a vector to a scalar.
Imagine <10,100,-20> == y , what would the result be?  Clearly the
second component is dominating, or should it only evaluate to true for
<0,1,0> == y ?  And what about <4,8,2> == <2,4,1> ?  The direction is
the same, yet the first one is twice as long as the second one.

> Or what's the error?

The documentation makes is clear that there are no comparisons of
vectors supported (section "Vector Operators"), not even those for
equality.

>   #local T0 = x;
>   #local T1 = 1;
>   #local T1 = (T0=y);
> This driggers the error : "Attempted to redefine float identifier as vector
> identifier." but a
> conditions should be represented as a boolean/float.

Keep in mind that x, y and z have a special meaning.  y is the vector
<0,1,0>, not a scalar.  And as you know from the documentation, there
are no comparison operators for vectors.  Since the parser assumes this
it will stop at the first vector (T0) it finds and not even see the
comparison operator that is following it.  However, I have to admit that
the error message is a bit confusing :-(


     Thorsten


Post a reply to this message

From: KalleK
Subject: Re: condition parsed as vector
Date: 15 Feb 2001 16:00:03
Message: <3a8c4353$1@news.povray.org>
Thank you, Thorsten.
I will write a little #macro that fit my needs (that is the condition is only true if
the vectors
are exactly the same - what I thought (Vector1=Vector2) would do)
Thinking about it - it's the right way it acts. I just did not think about it.

Thanx. Now I can go on pov-scripting.

cukk


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: condition parsed as vector
Date: 15 Feb 2001 19:21:54
Message: <3A8C7265.8ABD747@hotmail.com>
KalleK wrote:
> 
> Thank you, Thorsten.
> I will write a little #macro that fit my needs (that is the condition is only true
if the vectors
> are exactly the same - what I thought (Vector1=Vector2) would do)

Hello Kalle

You don't need a macro to do that.

This expression will help you to achieve the same:

vlength(Vector2 - Vector1)


Your (illegal) code;

#local T0 = x;
#local T1 = 1;
#local T1 = (T0=y);

could then be written like this:

#local T0 = x;
#local T1 = (vlength(y - T0) = 0);


You could even write the last line like this:

#local T1 = (!vlength(y - T0));

(But I will not recommend doing it that way.)


And, as you probably already know, you can
now use the T1 variable within other boolean
expressions.

E.g.:

#if (T1)
  #debug "T0 is equal to <0, 1, 0>"
#end


-- 
Best regards,

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok


Post a reply to this message

From: Chris Huff
Subject: Re: condition parsed as vector
Date: 16 Feb 2001 07:43:18
Message: <chrishuff-D99362.07430916022001@news.povray.org>
In article <3a8c3b87$1@news.povray.org>, "Thorsten Froehlich" 
<tho### [at] trfde> wrote:

> And as you know from the documentation, there
> are no comparison operators for vectors.

Actually, there are...they are done component by component, and the 
results are stored in another vector. In other words, < 1, 2, 3> = < 2, 
2, 3> will result in < 0, 1, 1>.

From the POV-Ray manual:
"Operations are performed on a component-by-component basis. For example 
<1,2,3> + <4,5,6> evaluates the same as <1+4,2+5,3+6>  or <5,7,9>. Other 
operations are done on a similar component-by-component basis. For 
example (<1,2,3> = <3,2,1>) evaluates to <0,1,0> because the middle 
components are equal but the others are not. Admittedly this isn't very 
useful but its consistent with other vector operations."

The problem is just that conditionals need float parameters.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: KalleK
Subject: Re: condition parsed as vector
Date: 16 Feb 2001 08:44:25
Message: <3a8d2eb9$1@news.povray.org>
Ok. I killed that strange macro:

  #macro CompV (V1, V2)
   ((!(V1.x=V2.x)|!(V1.y=V2.y)|!(V1.z=V2.z))=0)
  #end
(It was crazy, I know.)
and replaced it with your code.
Thank you Tor!

cukk


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: condition parsed as vector
Date: 16 Feb 2001 09:47:46
Message: <3a8d3d92$1@news.povray.org>
In article <chrishuff-D99362.07430916022001@news.povray.org> , Chris 
Huff <chr### [at] maccom>  wrote:

> From the POV-Ray manual:
> "Operations are performed on a component-by-component basis. For example
> <1,2,3> + <4,5,6> evaluates the same as <1+4,2+5,3+6>  or <5,7,9>. Other
> operations are done on a similar component-by-component basis. For
> example (<1,2,3> = <3,2,1>) evaluates to <0,1,0> because the middle
> components are equal but the others are not. Admittedly this isn't very
> useful but its consistent with other vector operations."

Interesting, I missed that part...


   Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: condition parsed as vector
Date: 16 Feb 2001 16:43:48
Message: <3A8D9E92.287058D3@hotmail.com>
KalleK wrote:
> 
> Ok. I killed that strange macro:
> 
>   #macro CompV (V1, V2)
>    ((!(V1.x=V2.x)|!(V1.y=V2.y)|!(V1.z=V2.z))=0)
>   #end
> (It was crazy, I know.)

Hello again Kalle.

Yes, that macro was a bit crazy !

Most people use DeMorgans laws to simplify logic
expressions, but for me it seems like you have 
used it to complicate the expression.

That macro could have been written like this:

#macro CompV(V1, V2)
  (V1.x = V2.x & V1.y = V2.y & V1.z = V2.z)
#end // macro CompV 


But maybe you knew that.


-- 
Best regards,

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok


PS.: For those of you that don't know DeMorgans laws 
for boolean expressions, here they are (in POV-style):
(In the following P and Q are boolean variables or expressions.)

(!(P & Q))   is equivalent to   (!P | !Q)
(!(P | Q))   is equivalent to   (!P & !Q)


From this follows that:

(!(!P | !Q))   is equivalent to   (P & Q)
(!(!P & !Q))   is equivalent to   (P | Q)


Here's an example:

"aa is neither 1 nor 4":

(aa != 1 & aa != 4)   is equivalent to   (!(aa = 1 | aa = 4))


And then another one:

"aa is greater than or equal to 1, and less than 4"

((aa >= 1) & (aa < 4))    is equivalent to   (!(aa < 1 | aa >= 4))


Another POV-related aspect of this is that it can be used 
to simplify (or rewrite) expressions with unions, intersections
and inverse statements:

The OR  operator:   |   corresponds to:   union   (or merge)
The AND operator:   &   corresponds to:   intersection
The NOT operator:   !   corresponds to:   inverse


Post a reply to this message

From: KalleK
Subject: Re: condition parsed as vector
Date: 17 Feb 2001 03:23:36
Message: <3a8e3508$1@news.povray.org>
Hi Tor Olav!

> But maybe you knew that.

Yes, I knew.
Somehow.
Ehm... at first I did not, but the next day I saw that it was late
last night...

> Another POV-related aspect of this is that it can be used
> to simplify (or rewrite) expressions with unions, intersections
> and inverse statements:
>
> The OR  operator:   |   corresponds to:   union   (or merge)
> The AND operator:   &   corresponds to:   intersection
> The NOT operator:   !   corresponds to:   inverse

and whats the difference ?
:-)
bad joke.

it's A&!B

And thanx for those DeMorgans laws. I'm loosing touch with mathematics
(having finished school a yaer ago) and it's always nice to get back
to it, to think about it. That's a reason why I'm poving.

cukk


Post a reply to this message

From: AC
Subject: Re: condition parsed as vector
Date: 18 Feb 2001 07:10:19
Message: <3a8fbbab@news.povray.org>
"KalleK" <kal### [at] gmxde> wrote in message news:3a8e3508$1@news.povray.org...
> Hi Tor Olav!
>
> > But maybe you knew that.
>
> Yes, I knew.
> > The OR  operator:   |   corresponds to:   union   (or merge)
> > The AND operator:   &   corresponds to:   intersection
> > The NOT operator:   !   corresponds to:   inverse
>
> and whats the difference ?
> :-)
LOL
Ambis


Post a reply to this message

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