GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2011-05-26 07:25:57

Rani_sputnik
Member
Registered: 2011-04-24
Posts: 18

voronoi diagrams

Voronoi diagrams take a bunch of points and calculate the closest point to each pixel/position/whatever. I found a use for them making pretty pictures smile  Mostly I wanted to post this for analysing because I need it to be as fast as possible (who doesn't?) and I think it's pretty much there. Basically it just jumps into 3d and draws a cone at each position on the grid, then the depth buffer does all the work of finding the intersections. Enjoy:

Expand// vor_create_from_object(obj,x,y,w,h,maxdist,precision)
// Creates a voronoi diagram using all instances of the object obj and their positions
// within the region x,y,width,height
// maxdist refers to how far the instances we be apart, if any instances are beyond
// this distance apart there will be dead zones on the surface
// Returns a surface that has pointers to the instances id
// precision refers to the quality of the diagram 
// Script by Rani_sputnik

var s,d;
s = surface_create(argument3,argument4)
d = draw_get_color()

d3d_start()
d3d_set_perspective(false)
d3d_set_projection_ortho(argument1,argument2,argument3,argument4,0)

surface_set_target(s)
draw_clear(0)
var n; n=0
repeat instance_number(argument0)
{
    i = instance_find(argument0,n)
    draw_set_color(i-100000)
    d3d_draw_cone(i.x-argument5,i.y-argument5,argument5,  i.x+argument5,i.y+argument5,0, -1,1,1,false,argument6)
    n += 1
}

surface_reset_target()
draw_set_color(d)
d3d_end()

return s

Note that I had to set it so that the colours drawn onto the voronoi surface are set to the instance id - 100000. Not that this is a big issue but I was pretty sure that there are 16 million+ colours, anyone got a reason as to why this could be happening? Cheers in advance smile

EDIT: NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

I just rolled on over to the creations topic and this was the first thing I saw listed by Daniel! I felt so smart, now I just feel like a copy-cat sad sad sad

Last edited by Rani_sputnik (2011-05-26 07:34:33)

Offline

#2 2011-05-26 15:24:08

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: voronoi diagrams

This sort of coincidence happens all the time in science, mathematics, technology, and art. It seems we are primed by our common environments to reach the same conclusions at the same time.

Excerpt from "In the Air" by Malcolm Gladwell, published in The New Yorker, May 12, 2008 wrote:

This phenomenon of simultaneous discovery—what science historians call "multiples"—turns out to be extremely common. One of the first comprehensive lists of multiples was put together by William Ogburn and Dorothy Thomas, in 1922, and they found a hundred and forty-eight major scientific discoveries that fit the multiple pattern. Newton and Leibniz both discovered calculus. Charles Darwin and Alfred Russel Wallace both discovered evolution. Three mathematicians "invented" decimal fractions. Oxygen was discovered by Joseph Priestley, in Wiltshire, in 1774, and by Carl Wilhelm Scheele, in Uppsala, a year earlier. Color photography was invented at the same time by Charles Cros and by Louis Ducos du Hauron, in France. Logarithms were invented by John Napier and Henry Briggs in Britain, and by Joost Bürgi in Switzerland.

"There were four independent discoveries of sunspots, all in 1611; namely, by Galileo in Italy, Scheiner in Germany, Fabricius in Holland and Harriott in England," Ogburn and Thomas note, and they continue:

The law of the conservation of energy, so significant in science and philosophy, was formulated four times independently in 1847, by Joule, Thomson, Colding and Helmholz. They had been anticipated by Robert Mayer in 1842. There seem to have been at least six different inventors of the thermometer and no less than nine claimants of the invention of the telescope. Typewriting machines were invented simultaneously in England and in America by several individuals in these countries. The steamboat is claimed as the "exclusive" discovery of Fulton, Jouffroy, Rumsey, Stevens and Symmington.

For Ogburn and Thomas, the sheer number of multiples could mean only one thing: scientific discoveries must, in some sense, be inevitable. They must be in the air, products of the intellectual climate of a specific time and place. It should not surprise us, then, that calculus was invented by two people at the same moment in history. Pascal and Descartes had already laid the foundations. The Englishman John Wallis had pushed the state of knowledge still further. Newton's teacher was Isaac Barrow, who had studied in Italy, and knew the critical work of Torricelli and Cavalieri. Leibniz knew Pascal's and Descartes's work from his time in Paris. He was close to a German named Henry Oldenburg, who, now living in London, had taken it upon himself to catalogue the latest findings of the English mathematicians. Leibniz and Newton may never have actually sat down together and shared their work in detail. But they occupied a common intellectual milieu. "All the basic work was done—someone just needed to take the next step and put it together," Jason Bardi writes in "The Calculus Wars," a history of the idea's development. "If Newton and Leibniz had not discovered it, someone else would have." Calculus was in the air.

Full Article: http://www.gladwell.com/2008/2008_05_12_a_air.html

I could also add to that list the simultaneous invention of error diffusion dithering by Floyd-Steinberg and Jarvis-Judice-Ninke, which I wrote about in another topic.

See? You are in good company. smile


Abusing forum power since 1986.

Offline

#3 2011-05-27 05:36:47

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: voronoi diagrams

Personally, my last one was re-inventing the lerp function, the one before that was the collision_line_first, well documented in my laser thread on the gmc. Anyway, what it means, I like to think, it that our minds are right out there with the great ones, like xot said... To me inventing/discovering something that was already there, hidden to you maybe, is a sign of true intelligence with the benefit of confirmation.

You stand a better change to invent/discover something of your own design than most so take comfort in that.

Personally I think it's weird, I often think of a concept or start to implement something, like a new tool only to discover on the gmc someone that beat me to the punch by just a few days... Me and this other guy on the gmc came up with like 5 almost identical ideas/concept in the course of 3 months...

Last edited by icuurd12b42 (2011-05-27 05:44:45)

Offline

#4 2011-05-27 09:12:49

Rani_sputnik
Member
Registered: 2011-04-24
Posts: 18

Re: voronoi diagrams

Wow there are people that study this? I didn't think it was that common. Sweet, I feel like a bit of a read haha. Cheers guys.

Offline

#5 2011-05-27 14:33:36

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: voronoi diagrams

In my carrier, we had a saying: Better get this out the door before the 100th monkey hears of this

Offline

Board footer

Powered by FluxBB