|
| 02 Apr 2012 08:36 PM |
It didn't look like Scripting Helpers could help me out, so I figured this belonged here so someone more experienced can share their opinion.
If I want to generate X amount of points onto a sphere, how do I distribute these points evenly along that sphere?
I know it's some sort of algebraic surface but I haven't been able to find a function to produce the desired result and I can't figure it out on my own. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2012 08:40 PM |
| Assuming it's mathematically possible to do this with any number of points... |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 02 Apr 2012 08:41 PM |
Look what I found using google:
import math def pointsOnSphere(N): N = float(N) # in case we got an int which we surely got pts = [] inc = math.pi * (3 - math.sqrt(5)) off = 2 / N for k in range(0, N): y = k * off - 1 + (off / 2) r = math.sqrt(1 - y*y) phi = k * inc pts.append([math.cos(phi)*r, y, math.sin(phi)*r]) return pts
for pt in pointsOnSphere(80): n = Application.ActiveSceneRoot.AddNull() n.size = 0.05 t = n.Kinematics.Global.Transform t.SetTranslationFromValues(pt[0], pt[1], pt[2]) n.Kinematics.Global.Transform = t
Using the following code, I'm sure making a Lua version won't be hard. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2012 08:50 PM |
| Sorry to be a burden, but all that's confusing. I'm only really experienced with Lua. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 02 Apr 2012 09:12 PM |
My translation:
function PointsOnSphere(Points) local pts = {} local off = 2 / Points for k=0, Points do local y = k* off - 1 + (off / 2) local r = math.sqrt(1 - y*y) local phi = K * inc table.insert(pts, Vector3.new(math.cos(phi)*r, y, math.sin(phi)*r)) end return pts; end
function GeneratePoints(Num) local pt for _, pt in pairs(PointsOnSphere(Num)) do local n n.Size = Vector3.new(0.05) --????? IDK WUT? end |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2012 09:19 PM |
A decent try but there's a pretty big problem.
I can't define "phi" because "K" and "inc" are nil variables. nil*nil = nil. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2012 09:21 PM |
Scratch that. "K" isn't nil, but "inc" is. What are you, "inc"? |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 02 Apr 2012 09:23 PM |
| Why don't you just google it? Seeing as there's about 50 million results. |
|
|
| Report Abuse |
|
|
Charl3s7
|
  |
| Joined: 07 Dec 2007 |
| Total Posts: 4146 |
|
|
| 02 Apr 2012 09:27 PM |
| In the python one, inc = math.pi * (3 - math.sqrt(5)). |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2012 09:33 PM |
| thanks guys, i figured it out! |
|
|
| Report Abuse |
|
|