From Forces
From a force perspective, "oribts" happen because there is a strong inward force happening. In particular,
ma = v^2 / r where m is the mass, a is the acceleration (so ma = F, force), r is the radius and v is the velocity.
If you're in a stable orbit, r and v are constant. m will also be constant.
(Neglect gravity:) If we compare this to, for instance, a BodyPosition, we know that the force applied will be precisely inward, and since the distance isn't changing the force applied will be constant. So we just need to get the right amount of push inwards (in addition to compensating for gravity with a BodyForce upwards)
In practice, that won't work at all, though. The errors will accumulate and it will just sporadically orbit around.
Computing Orbit Ourself
Instead, we should probably manage the orbit directly -- no body objects at all, and just set the CFrame of the orbiting (anchored) object.
We can make a circle using cos(t), 0, sin(t):
while wait() do
local t = tick() * (math.pi * 2) * 1.5
local orbit = Vector3.new( math.cos(t), 0, math.sin(t) )
elec.CFrame = CFrame.new( nucleus.Position + orbit * radius )
end
This will only make a flat orbit, though. If we want orbits at other angles, we should just think in a different way. The above math is equivalent to this:
local orbit = Vector3.new(1, 0, 0) * math.cos(t) + Vector3.new(0, 0, 1) * math.sin(t)
elec.CFrame = CFrame.new( nucleus.Position + orbit * radius )
The important property here is that Vector3.new(1, 0, 0) and Vector3.new(0, 0, 1) are perpendicular.
In order to get random perpendicular vectors, we could do something crazy like this:
function randomVector()
local x
repeat
x = Vector3.new( math.random()*2-1, math.random()*2-1, math.random()*2-1)
until x.magnitude <= 1
return x
end
function randomPerpendicularPair()
local a = randomVector()
local b = randomVector()
return a:Cross(b).unit, b.unit
end
local u, v = randomPerpendicularPair()
while wait() do
local t = tick() * (math.pi * 2) * 1.5
local orbit = u * math.cos(t) + v * math.sin(t)
elec.CFrame = CFrame.new( nucleus.Position + orbit * radius )
end
On the "stereotypical atom"
You're referring to the Bohr model which is at least useful to use for properties, but of course, like most models taught in school, is completely inaccurate (physically speaking).
1 comment
I think it may be best to weld it then edit the weld to rotate around it... I haven't learned enough welding to help you with this theory , sorry.