# Garry's Mod gamemode scripting (lua) - How do I tell if an object is inside a hollow cylinder?

I'm fiddling about with gMod trying to make a gamemode where you have to throw a piece of cake into a cylinder that spawns on the map.

This is the code I'm using to spawn the cylinder:

local ent = ents.Create( "prop_physics" )
ent:SetModel("models/props_phx/construct/windows/window_curve360x1.mdl")
ent:SetPos( Vector(math.random(100,2500), math.random(1500,-1000), 150) )
--ent:SetPos( math.random(-1500,-2500), math.random(-1500,-2500), 100 )
ent:Spawn()

undo.Create( "Spawned_Cylinder" )
undo.SetPlayer ( self.Owner )
undo.Finish()


The cake throwing part is basically just a SWEP that shoots the 'cakehat' prop. How would I test whether there is a piece of a cake inside the cylinder?

You take the center of the cake and determine if it's within distance of the radius and also within the distance of the height. It's been a while since I've done gmod lua so bear with me.

local cylinderCenterPos = Vector(0,0,0)
local cylinderHeight = 2
local cakePos = cake.GetPos()

local radiusDist = math.sqrt(math.pow(cylinderCenterPos.x - cakePos.x,2) + math.pow(cylinderCenterPos.y - cakePos.y,2)) --Horizontal axes
local heightDist = math.abs(cylinderCenterPos.z - cakePos.z) --Up axis