Simulation / python / grasshopper

Hello everyone ,
First i wanted to apologize for my English , its not my native language .
I am working on a simulation project for a while now , and since i am new to scripting it was very hard for me but i managed it till now some how , i asked a lot of questions here and the answers helped me a lot , until now that my script reached to a critical point and suddenly it started to give me some strange errors.
The funny thing is each time i ran the program the error change and some times it actually work for a while then it start to give error .
i really have no idea what is the problem , i tried anything that came to my mind but it just does not make any sense to me .
so please take a look at my script and help me if you can .
thanks a lot .
Arash (11.6 KB)

it looks like the problem start when i try to project points to the surface but as i said some times it works a bit !!!

You might try posting the Python script in the scripting category here on the forum as well for help. I can’t tell what the GH definition is intended for.

Hello @BrianJ , thank you for your reply , i will post it in the scripting category .
as for what GH definition is intend for , its a circle packing algorithm which i am trying to simulate it , i solved the last error and now the definition is one step further .
now my the definition works correctly with less than 10 point , here is the definition which work correct and have less than 10 point : (11.2 KB)

but right after i increase the number of points to more than 10 (( 13 in file )) it gives me an strange error :
Runtime error (InvalidCastException): Specified cast is not valid.
i searched for the error but it seems like there is nothing of this error in python , all i found was for C# and other languages .
here is second file : (11.6 KB)

so please take a look at these two files , an help me plz .
thank you .