0
$\begingroup$

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?

a particle above a disk in 3d space

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

$\endgroup$
  • $\begingroup$ Thank you all for answering! You have all gave great answers and have been very helpful with my understanding of this problem $\endgroup$ – Blue7 Jan 4 '14 at 12:05
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thankyou very much. Although are you certain this will work? As sharkos has pointed out, unitvec1 multiplied by the radius will not give the "vector between disk center and point on the perimeter closest to the particle" as I thought it would. $\endgroup$ – Blue7 Jan 3 '14 at 16:01
  • $\begingroup$ What I've called pvec is the projection of the center-to-particle vector onto the $xy$ plane. Notice that to create "unitvec1", I've normalize "pvec" instead of normalizing "vec1". (This is much the same as @Sharkos's normalization of vec2). Thus radius * unitvec1 really IS a point on the boundary circle. So I'm pretty certain that this code will work fine. BTW, notice that in the "if" clause, I've got a "return" statement -- you're supposed to compute the answer and quit at that point, not continue on through the rest of the code. $\endgroup$ – John Hughes Jan 3 '14 at 16:44
0
$\begingroup$

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$.

$\endgroup$
  • $\begingroup$ Thank you for your answer. Can you please tell me what d, R, and theta represent in your equation, and how I would find them? $\endgroup$ – Blue7 Jan 3 '14 at 15:35
  • $\begingroup$ My attempt at an answer is written is pseudo code, not a real programing language. the equals sign is an equality, not a "gets" as it would be in a programming language. I just formatted it this way to show my working out. $\endgroup$ – Blue7 Jan 3 '14 at 15:36
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ "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" I see where i've gone wrong, because I have modified unitvec1 by setting the z component to 0, it is no longer a unit vector and therefore when multiplied by the radius it does not give the radius vector. However, I'm not sure if your solution will work. To get vec 2 in the first place I will need a unit vector that points in the direction towards the min point $\endgroup$ – Blue7 Jan 3 '14 at 15:57
  • $\begingroup$ The direction of the vector formed by projecting onto $z=0$ is correct regardless of its normalization, so this should work. $\endgroup$ – Sharkos Jan 3 '14 at 16:03
  • $\begingroup$ To be slightly more precise, you should (a) project by setting $z$ component to zero, (b) check if result is zero (probably within numerical error), (c) if so, just return vertical distance; (d) if not, compute (radius / norm) * projected vector and use that in computing vec3. $\endgroup$ – Sharkos Jan 3 '14 at 16:08
0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.