POV-Ray : Newsgroups : povray.newusers : single point on spline and a vector: comparison Server Time
25 Nov 2024 03:48:04 EST (-0500)
  single point on spline and a vector: comparison (Message 1 to 5 of 5)  
From: marabou
Subject: single point on spline and a vector: comparison
Date: 2 Nov 2006 13:47:29
Message: <454a3d41@news.povray.org>
hello,
for some reason I want to check if one point at spline-creation time is
equal to one point in an array.
More concrete:
There is an array[] of vectors which holds points of one future spline. 
A macro creates a spline from it. While this macro creates spline I wish to
compare if actual processed point hits one predefined point from array[x].

pseudo-code:
>>>>>>>>>>>>>>>>>>>>>>>>
// define spline
#declare splinepoints = array[]{<x,y,z>,...}

// create spline
#declare splinepath = spline{cubic_spline #while...}

// draw balls on splinepath
#macro happyspline(splinepath)
        #while (clock_counter <= maxpoint)
                sphere {
                        splinepath(clock_counter), radius
                }
                // the comparison, which fails:
                #if ( splinepath(clock_counter) = splinepoints[10] )
                        "HIT"
                #end
                clock_counter += anystep
        #end //while
#end //macro
<<<<<<<<<<<<<<<<<<<<<<<<<

Then comes a parse error: "Float expected but vector or color expression
found."
And I ask: Why is splinepath(at_one_moment) no vector? What did I wrong?


Post a reply to this message

From: Charles C
Subject: Re: single point on spline and a vector: comparison
Date: 2 Nov 2006 16:30:00
Message: <web.454a621739860a3174eed8480@news.povray.org>
It's difficult to debug what's likely a syntax error when looking at psuedo
code.  So not getting into that, what line of actual code is showing the
error?

On the another note, for each defined point where are you storing the
"value" which says how far along it is on the spline?  I deal with splines
in arrays of 4D vectors rather than 3 so that the same vector that holds
the 3D points will also hold the "value" position for each point.
Unfortunately this means that when converting it to a spline it looks
something like this for each value of the array:

#local Tempfloat=The_Array[ctr].t;
Tempfloat,  <The_Array[ctr].x, The_Array[ctr].y, The_Array[ctr].z>

Using the Tempfloat variable was a workaround - Pov-Ray didn't like
The_Array[ctr].t directly in the spline statement.

> And I ask: Why is splinepath(at_one_moment) no vector? What did I wrong?

Have you tried something like the following?
#debug concat(" x = ", str(splinepath(clock_counter).x,5,5),
              " y = ", str(splinepath(clock_counter).y,5,5),
              " z = ", str(splinepath(clock_counter).z,5,5),
              " ")

Hope something here is useful... :)
Charles


marabou <not### [at] availableyet> wrote:
> hello,
> for some reason I want to check if one point at spline-creation time is
> equal to one point in an array.
> More concrete:
> There is an array[] of vectors which holds points of one future spline.
> A macro creates a spline from it. While this macro creates spline I wish to
> compare if actual processed point hits one predefined point from array[x].
>
> pseudo-code:
> >>>>>>>>>>>>>>>>>>>>>>>>
> // define spline
> #declare splinepoints = array[]{<x,y,z>,...}
>
> // create spline
> #declare splinepath = spline{cubic_spline #while...}
>
> // draw balls on splinepath
> #macro happyspline(splinepath)
>         #while (clock_counter <= maxpoint)
>                 sphere {
>                         splinepath(clock_counter), radius
>                 }
>                 // the comparison, which fails:
>                 #if ( splinepath(clock_counter) = splinepoints[10] )
>                         "HIT"
>                 #end
>                 clock_counter += anystep
>         #end //while
> #end //macro
> <<<<<<<<<<<<<<<<<<<<<<<<<
>
> Then comes a parse error: "Float expected but vector or color expression
> found."
> And I ask: Why is splinepath(at_one_moment) no vector? What did I wrong?


Post a reply to this message

From: Chris B
Subject: Re: single point on spline and a vector: comparison
Date: 2 Nov 2006 19:44:09
Message: <454a90d9$1@news.povray.org>
"marabou" <not### [at] availableyet> wrote in message 
news:454a3d41@news.povray.org...
> hello,
> I want to check if one point at spline-creation time is
> equal to one point in an array.
>  ... snip ...
>                #if ( splinepath(clock_counter) = splinepoints[10] )
>  ... snip ...
> Then comes a parse error: "Float expected but vector or color expression
> found."
> And I ask: Why is splinepath(at_one_moment) no vector? What did I wrong?
>

Hi,
splinepath(clock_counter) does return a vector, but, in an #if statement you 
need something that evaluates to a 'float expression that is interpreted as 
a boolean value' and vector1=vector2 doesn't give you that, which is why you 
get the error that complains that it came across a vector rather than 
finding a float.

I believe you'll need to test the individual elements of the vector, (though 
someone may know an easier way):

#declare A = <1,1,1>;
#declare B = <1,1,1>;
#if (A.x=B.x & A.y=B.y & A.z=B.z)
  sphere {0,1 pigment {color rgb 1}}
#end

Also, even if the condition is theoretically met, you may well run into 
precision errors that you'll need to deal with.
ie if splinepath(clock_counter) returns <1.0000001,0.999999999,1.000000005> 
then you'll need to handle that in your logic.
Typically you could end up with something like:

#declare Threshold = 0.001;
#if (A.x-B.x<Threshold &
      A.y-B.y<Threshold &
      A.z-B.z<Threshold)

Regards,
Chris B.


Post a reply to this message

From: Slime
Subject: Re: single point on spline and a vector: comparison
Date: 3 Nov 2006 02:07:31
Message: <454aeab3$1@news.povray.org>
> #if (A.x-B.x<Threshold &
>       A.y-B.y<Threshold &
>       A.z-B.z<Threshold)

You're going to want to put abs() around the left hand sides of those
comparisons.

A simpler (though slower) option is

#if ( vlength(A-B) < Threshold )

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Warp
Subject: Re: single point on spline and a vector: comparison
Date: 3 Nov 2006 07:11:07
Message: <454b31db@news.povray.org>
Slime <fak### [at] emailaddress> wrote:
> > #if (A.x-B.x<Threshold &
> >       A.y-B.y<Threshold &
> >       A.z-B.z<Threshold)

> A simpler (though slower) option is

> #if ( vlength(A-B) < Threshold )

  Slower?-o

  There's much less to parse there. POV-Ray will spend 99% of the time
parsing that expression and 1% of the time calculating its result. You
do the math on which option is faster.

-- 
                                                          - Warp


Post a reply to this message

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