How to create random point on sphere?

  • Simply, how do I manipulate a point’s coordinates so that the point lies on the sphere’s “surface” ?
  • How do I generate 360 points (x,y,z) and make sure they land on a sphere whose center is (0,10,0) and its radius is 10 ?

I have just solved this problem.

local function CreateRandomPointOnASphere(centre,radius)
	local b = math.random(0,360)
	local y0 = math.cos(b)
	local y1 = math.sin(b)
	y0 *= radius
	y1 *= radius
	local a = math.random(0,360)
	local x0 = math.cos(a)
	local x1 = math.sin(a)
	x0 *= y1
	x1 *= y1
	return Vector3.new(centre.X + y0,centre.Y + x1,centre.Z + x0)
end
for i = 0, 360 do
	local a = Instance.new("Part")
	a.Parent = workspace
	a.Anchored = true
	a.Size = Vector3.new(1,1,1)
	local pos = CreateRandomPointOnASphere(Vector3.new(0,10,0),10)
	a.Position = pos
	task.wait()
end

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.