Minimum distance between a disk in 3d space and a point above the disk How can I calculate the minimum distance between a point on the perimeter of a disk in 3d space and a point above the disk?
For example, there is a disk in 3d space with center [0,0,0]. It has radius 3 and lies flat on the x,y plane. If there is a particle above the disk at [5,5,5], how do I calculate the minimum distance from this particle to a point on the perimeter of the disk?

Here is my attempt so far:
vec1 = vector between disk center and particle
vec1 = [(5 - 0), (5 - 0), (5 - 0)]
vec1 = [5,5,5]

unitvec1 = unit vector in direction of vec1
unitvec1 = vec1/norm(vec1)
unitvec1 = [0.5774, 0.5774, 0.5774]

vec2 = vector between disk center and point on the perimeter closest to the particle
vec2 = disk radius * unitvec1, and make z element = 0
vec2 = 3 * [0.5774, 0.5774, 0]
vec2 = [1.7321, 1.7321, 0]

vec3 = vector between particle and point on the perimeter closest to the particle
vec3 = vec1 - vec2
vec3 = [3.2679, 3.2679, 5.0000]

So the min distance is
norm(vec3) = 6.8087

But this method doesn't always work. If I try it with disk center [0,0,0], particle location [0,0,6], and disk radius 9, it gives the minimum distance to be 6. this can't be correct, because the distance between the center of the disk and the particle will be 6, so the distance to the perimeter must be larger.
What am I doing wrong, and how should I actually calculate this?
Thanks!
note: I am using pseudo code, not an actual programing language 
 A: I am not familiar with the programming language you are using, but here is how I would set up the problem. Let the point be at $(x,y,z)$. Then
$$d^2 = (x - R \cos(\theta))^2 + (y - R \sin(\theta))^2 + z^2 = R^2-2\,\sin \theta\,y\,R-2\,\cos \theta\,x\,R+z^2+y^2+x^2$$
If $x=y=0$ then distance does not depend on $\theta$. Or else it is at the angle satisfying:
$$ y \cos(\theta)=x \sin(\theta)$$
Make sure you use $\text{atan2}$ to get the angle in the right quadrant.
You could always rotate the $x-y$ plane so $y=0$ and $x>0$!
Added in response to OP's question:
R: radius of the disk
$\theta$: Angle of a point on the rim, measured from the $x$ axis.
d: Distance from the point $P$ to the point on the rim (at angle $\theta$)
$(x,y,z)$: coordinates of the the point $P$.
A: Your logic is wrong because you make the wrong thing a unit vector. The length of your vec2 is not necessarily equal to the radius of the disc, because it is equal to the radius multiplied by a vector which is some component of the unit vector unitvec1.
Instead of normalizing vec1, you should normalize vec2.
In this case, be aware that vec2 might be zero (as in your final example). Thus when normalizing you should check if this happens, and if so arbitrarily set vec2 to any point on the diameter in this case.
A: Your code is almost completely correct (and avoids the use of atan2, which is nice). The one problem you have is that when the vector from the disk-center to your point happens to point perpendicular to the disk, i.e., when the test point happens to be exactly above the disk's center, it falls apart: projecting that vector to the $xy$-plane gives the zero vector, whose tip does not lie on the disk's boundary circle. 
Here's replacement code (mostly yours):
vec1 = vector between disk center and particle
vec1 = [(5 - 0), (5 - 0), (5 - 0)]
vec1 = [5,5,5]

pvec1 = vec1 with its z-coordinate set to 0. 
if (norm (pvec1) = 0 ): 
   answer = sqrt( norm(vec1) * norm(vec1) + radius * radius )
   return

unitvec1 = unit vector in direction of pvec1
unitvec1 = pvec1/norm(pvec1)
unitvec1 = [0.7071, 0.7071, 0]

vec2 = vector between disk center and point on the perimeter closest to the particle
vec2 = disk radius * unitvec1
vec2 = 3 * [0.7071, 0.7071, 0]
vec2 = [2.1..., 2.1..., 0]

vec3 = vector between particle and point on the perimeter closest to the particle
vec3 = vec1 - vec2

So the min distance is
norm(vec3) = 6.8087

That'll handle the special case on which your current code is failing. Note that you might want to replace the test "norm (pvec1) = 0" with "norm (pvec1) < .001" to make the code a bit more numerically stable, and introduce almost no error. 
A: I'm going to answer my own question, I've just been told a much easier way to calculate this.
Let R = radius of disk
Let r = distance from disk center to projection of particle on x,y plane
so r = ((5^2)+(5^2))^0.5 = 4.071
Distance between concentric circles = ((R-r)^2)^0.5 = 4.071
Height of particle above disk = 5
Rmin can then be calculated using Pythagorean theorem 
Rmin = ( (4.071^2) + (5^2) )^0.5 = 6.448
