I’m trying to get 3d positions (they will be used as origin positions for rays) along the surface of a ball part. I figure the center of the ball position along with the radius of it there should be some math that could get points on the surface. I’m doing something like this already, but have only figured out how to get the points along the circumference:
local numRays = 10
local angleBetweenRays = 360 / numRays
local function checkForBallCollision(zMove)
local ballCenter = Ball.Position
local centerRay = workspace:Raycast(ballCenter,Vector3.new(0,0,zMove+BallRadius),checkForCollisionParams)
if centerRay then return centerRay, centerRay.Distance-BallRadius end
--Outside circumference ray loop
for i = 0, numRays do
local circumferenceAngle = i * angleBetweenRays
local x = ballCenter.X + math.cos(math.rad(circumferenceAngle)) * BallRadius
local y = ballCenter.Y + math.sin(math.rad(circumferenceAngle)) * BallRadius
local circumferenceRayOrigin = Vector3.new(x, y, ballCenter.Z)
local circumferenceRay = workspace:Raycast(circumferenceRayOrigin,Vector3.new(0,0,zMove),checkForCollisionParams)
if circumferenceRay then
return circumferenceRay, circumferenceRay.Distance
end
end
end
What I want now is help making another for loop similar to the one already in there, that will either be a smaller circle that is placed on the surface of the ball I just need to be able to adjust the angle so I can make multiple more loops if need be.
Even better option would be a way to just evenly distribute points all across the surface of the ball facing the Z direction.
Hopefully I’ve clearly explained what I’m trying to accomplish if not please ask for clarification also thanks in advance.
What I know is if you’re asking to calculate the surface point of a sphere, you’re asking for calculus. If you want to spawn points on top of the surface of a sphere, I’d rotate the object’s look vector and perform its transformation in the direction of said look vector.
To distribute random points on any surface you need to “normalize” your random output to the amount of space for each other variable. Someone had just asked how to do this for a circle so I’ll use that case as an example and I think you’ll be able to adapt that for your sphere:
randomly pick a radius and an angle, this will give you a random point on the circle but points will be clustered near the center where there’s less area. You want to undo this effect by making higher radiuses more likely. We need a function that undoes the slope of this line, so that an r of 0 is almost impossible. (Brb checking my math, but maybe you can see where I’m going with this?)
bit late but you can probably look into something called the fibonacci sphere and then using points generated by that, basically it creates points evenly in a sphere that you can probably use for that