generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

How do I generate points evenly along a sphere?

Previous Thread :: Next Thread 
EdduTheArdo is not online. EdduTheArdo
Joined: 16 Mar 2008
Total Posts: 3765
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
EdduTheArdo is not online. EdduTheArdo
Joined: 16 Mar 2008
Total Posts: 3765
02 Apr 2012 08:40 PM
Assuming it's mathematically possible to do this with any number of points...
Report Abuse
Quenty is online. 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
EdduTheArdo is not online. EdduTheArdo
Joined: 16 Mar 2008
Total Posts: 3765
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 is online. 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
EdduTheArdo is not online. EdduTheArdo
Joined: 16 Mar 2008
Total Posts: 3765
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
EdduTheArdo is not online. EdduTheArdo
Joined: 16 Mar 2008
Total Posts: 3765
02 Apr 2012 09:21 PM
Scratch that. "K" isn't nil, but "inc" is.
What are you, "inc"?
Report Abuse
Quenty is online. 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 is not online. 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
EdduTheArdo is not online. EdduTheArdo
Joined: 16 Mar 2008
Total Posts: 3765
02 Apr 2012 09:33 PM
thanks guys, i figured it out!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image