 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <3a8c3198$1@news.povray.org> , "KalleK" <kal### [at] gmx de>
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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] hotmail com
http://www.crosswinds.net/~tok
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <3a8c3b87$1@news.povray.org>, "Thorsten Froehlich"
<tho### [at] trf de> 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] mac com, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tag povray org, http://tag.povray.org/
<><
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <chrishuff-D99362.07430916022001@news.povray.org> , Chris
Huff <chr### [at] mac com> 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] trf de
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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] hotmail com
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"KalleK" <kal### [at] gmx de> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |