POV-Ray : Newsgroups : povray.binaries.scene-files : Quicksort in PoV-Ray? Server Time
2 Sep 2024 00:15:03 EDT (-0400)
  Quicksort in PoV-Ray? (Message 1 to 3 of 3)  
From: Jörg 'Yadgar' Bleimann
Subject: Quicksort in PoV-Ray?
Date: 20 Nov 2003 01:13:29
Message: <3FBC6A11.C6E5111B@gmx.de>
High everybody!

As a development of my "From Pole to Pole" animations, I began with
customizable general inter-continental flight/orbital
animations, where not only the current geographical coordinates, the
total distance travelled and the time elapsed since start
are displayed, but also the six or eight nearest of all capitals of the
world.

It's obvious that I have to sort the distances of the capitals once
again in the calculation of each frame, so I looked up the
Quicksort algorithm in my C tutorial. But there, Quicksort is
implemented as a recursive function (which returns no value),
now my question: is #macro equivalent to "non-returning" functions? Or
do I have to do it all as a series of nested loops?

Here is what I programmed up to now:

#declare buf;
#declare left=0;
#declare right=dimension_size(Dists, 1);
#declare m=Dists[(left+right)/2][1];
#declare i=left;
#declare j=right;
#while (left<j | i<right)
  #if (links<j) // uncompleted!
  #while(i>=j)
    #while (Dists[i][1]<m) #declare i=i+1; #end
    #while (Dists[j][1]>m) #declare j=j-1; #end
    #if (i>=j)
      #declare buf=Dists[i][1];
      #declare Dists[i][1]=Dists[j][1];
      #declare Dists[j][1]=buf;
      #declare i=i+1;
      #declare j=j-1;
    #end
  #end

#end


See you in Khyberspace!

Yadgar

Now playing: Curious Electric (Jon and Vangelis)


Post a reply to this message

From: Christopher James Huff
Subject: Re: Quicksort in PoV-Ray?
Date: 29 Nov 2003 21:40:32
Message: <cjameshuff-44E132.21404029112003@netplex.aussie.org>
In article <3FBC6A11.C6E5111B@gmx.de>,


> It's obvious that I have to sort the distances of the capitals once
> again in the calculation of each frame, so I looked up the
> Quicksort algorithm in my C tutorial.

You might want to have a look at arrays.inc as well...


> But there, Quicksort is
> implemented as a recursive function (which returns no value),
> now my question: is #macro equivalent to "non-returning" functions? Or
> do I have to do it all as a series of nested loops?

I'm not sure what you mean by macros being equivalent to non-returning 
functions. There is no requirement that a macro return a value...and 
recursion with macros does work.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Jörg 'Yadgar' Bleimann
Subject: Re: Quicksort in PoV-Ray?
Date: 30 Nov 2003 09:36:36
Message: <3FCA0F26.154101D4@gmx.de>
High!

Christopher James Huff schrieb:

> You might want to have a look at arrays.inc as well...
>
> > But there, Quicksort is
> > implemented as a recursive function (which returns no value),
> > now my question: is #macro equivalent to "non-returning" functions? Or
> > do I have to do it all as a series of nested loops?
>
> I'm not sure what you mean by macros being equivalent to non-returning
> functions. There is no requirement that a macro return a value...and
> recursion with macros does work.

Thank you for your suggestions... but meanwhile, I found it out on my own,
see "Heuraka! It works!".
I just translated the code from my C tutorial to PoV-Ray, and it works
perfectly!

See you in Khyberspace!

Yadgar


Post a reply to this message

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