This was tricky
function is_in_cylinder(%pt, %vec, %rad, %ht, %norm)
// "pt" is the point you're checking
// "vec" is actually the bottom of the cylinder
// "rad" and "ht" are the radius and height of the cylinder
// "norm" is the normalized vector relative to the bottom of the cylinder
{
%top = VectorAdd(%vec, VectorScale(%norm, %ht SPC %ht SPC %ht));
%center = VectorAdd(%vec, VectorScale(%norm, (%ht/2) SPC (%ht/2) SPC (%ht/2)));
%vec1 = VectorSub(%pt, %top);
%vec2 = VectorSub(%top, %vec);
%dist = mAbs( VectorCross(%vec1, %vec2) ) / VectorLen(%vec2);
if( %dist > %rad ) return false;
else
{
%start = 0;
%hit = VectorScale(%norm, %start);
while( true )
{
if( VectorDist(%pt, %hit) - %dist < 0.005 )
break;
else if( %start > %ht )
return false;
%start += 0.005;
%hit = VectorScale(%norm, %start);
}
if( VectorDist(%hit, %center) > VectorDist(%vec, %center) )
return false;
else
return true;
}
}