Posted 25 August 2014 - 11:51 PM
Hi there,
I'm using the midpoint algorithm for circles to generate ordered pairs for my turtle. This has been done in many other codes, but I'd like to try a new optimization method: I want to sort the ordered pairs by their polar angle.
ri = math.sqrt(xi2 + yi2)
thetai = math.asin(yi / ri)
I think I know that table.sort requires the "key" column to be continuous integers. So, I thought maybe I could put x in one table and y in another, and write a new sort function that iterates over table.x and table.y to solve for table.theta, sort that, and then apply table.theta's "sorting code" to table.x and table.y.
But I'm pretty new to Lua. Before I go any farther, may I ask if this has been done before? Is there a more obvious solution?
Thanks!
Not sure it will be helpful in this particular case, but my code is at: http://pastebin.com/safRUyjh . This is around line 350…
I'm using the midpoint algorithm for circles to generate ordered pairs for my turtle. This has been done in many other codes, but I'd like to try a new optimization method: I want to sort the ordered pairs by their polar angle.
ri = math.sqrt(xi2 + yi2)
thetai = math.asin(yi / ri)
I think I know that table.sort requires the "key" column to be continuous integers. So, I thought maybe I could put x in one table and y in another, and write a new sort function that iterates over table.x and table.y to solve for table.theta, sort that, and then apply table.theta's "sorting code" to table.x and table.y.
But I'm pretty new to Lua. Before I go any farther, may I ask if this has been done before? Is there a more obvious solution?
Thanks!
Not sure it will be helpful in this particular case, but my code is at: http://pastebin.com/safRUyjh . This is around line 350…
Edited on 25 August 2014 - 10:11 PM