Results 1 to 8 of 8

Math Help - Help with distance in square problem...

  1. #1
    Senior Member
    Joined
    Sep 2009
    Posts
    299

    Angry Help with distance in square problem...

    If I have a square of length n (the center of the square is on the origin), then if in the interior and boundary of the square, I have the point (x,y), and an angle theta, how do I get the distance of the length of the line connecting (x,y) to the edge of the square in the direction of theta?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor ebaines's Avatar
    Joined
    Jun 2008
    From
    Illinois
    Posts
    1,051
    Thanks
    288

    Re: Help with distance in square problem...

    Start by calculating the length of the line from the origin to the edge:

    For theta between -45 and +45 degrees h= n/(2 cos(theta)),
    For theta between 45 and 135 degrees h = n/(2 sin(theta))
    For theta between 135 and 225 degrees h = -n/(2 cos(theta)),
    For theta between 225 and 315 degrees h = -n/(2 sin(theta))

    The distance from the origin to (x,y) is sqrt(x^2+y^2). Hence the length from (x,y) to the edge is h-sqrt(x^2+y^2).
    Attached Thumbnails Attached Thumbnails Help with distance in square problem...-length.jpg  
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Senior Member
    Joined
    Sep 2009
    Posts
    299

    Re: Help with distance in square problem...

    This works nicely, but I realized my problem was more complex . I shall restate the question.

    In the cube in a 3d grid, where the origin is the center of the cube. If I have an arbitrary point on the cube (x1,y1,z1), and a direction vector (x2,y2,z2), and half of the length of the cube is n (so (2n)^3 = volume of cube), how do I get the distance of the line that connects the (x1,y1,z1) point to the edge of the cube in the direction of the directional vector (x2,y2,z2)?

    Thanks
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor ebaines's Avatar
    Joined
    Jun 2008
    From
    Illinois
    Posts
    1,051
    Thanks
    288

    Re: Help with distance in square problem...

    hello sneaky. Sorry for my delay in getting back to you on this.

    Let's call the unit vector that defines the direction from the point (x2,y2,z2) to be a \hat i + b \hat j + c \hat k, where  \hat i,  \hat j, and  \hat k represent the unit vectors in the x, y and z direction, respectively, and the magnitudes of a, b and c are:

     a = \frac {x_2} {\sqrt{ x_2^2 + y_2^2 + z_2^2}}
     b = \frac {y_2} {\sqrt{ x_2^2 + y_2^2 + z_2^2}}
     c = \frac {z_2} {\sqrt{ x_2^2 + y_2^2 + z_2^2}}

    Now we need to find the factor L that makes the vector L \times (a \hat i + b \hat j + c \hat k) run into a face of the cube. This requires comparing the factors L for three cases: when the vector reaches the plane x = \pm n/2, when it reaches y = \pm n/2, and when it reaches z = \pm n/2. Let's call these factors Lx, Ly, and Lz. Then:

    1. Distance to x = \pm n/2:
    If a>0, L_x = \frac {(n/2-x_1)} a

    If a<0, L_x = \frac {(-n/2-x_1)} a

    If a = 0, then L_x = \infty

    2. Distance to y = \pm n/2:

    If b>0, L_y = \frac {(n/2-y_1)} b

    If b<0, L_y = \frac {(-n/2-y_1)} b
    If b = 0, then L_y = \infty

    3. Distance to z = \pm n/2:
    If c>0, L_z = \frac {(n/2-z_1)} c

    If c<0, L_z = \frac {(-n/2-z_1)} c

    If c = 0, then L_z = \infty

    Now compare the values for L_x, L_y and L_z, and pick the smallest one - that's the distance to the nearest face of the cube.
    Last edited by ebaines; December 19th 2011 at 07:39 AM.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Senior Member
    Joined
    Sep 2009
    Posts
    299

    Re: Help with distance in square problem...

    I have two questions

    1) Does the n value here represent half the length of a side of the cube or the full length?

    2) Your last statement says "that's the distance to the nearest face of the cube. ". So then which is the distance that connects the point to the intersection of the cube in the direction of the directional vector?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor ebaines's Avatar
    Joined
    Jun 2008
    From
    Illinois
    Posts
    1,051
    Thanks
    288

    Re: Help with distance in square problem...

    Quote Originally Posted by Sneaky View Post
    I have two questions

    1) Does the n value here represent half the length of a side of the cube or the full length?
    n = the length of a side (i.e., the center of the faces of the cube are each n/2 from the origin)

    Quote Originally Posted by Sneaky View Post
    2) Your last statement says "that's the distance to the nearest face of the cube. ". So then which is the distance that connects the point to the intersection of the cube in the direction of the directional vector?
    What I meant is that this is the distance in the direction (x2,y2,z2) to intersect a face.
    Last edited by ebaines; December 19th 2011 at 08:15 AM.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor
    Joined
    Dec 2007
    From
    Ottawa, Canada
    Posts
    3,099
    Thanks
    67

    Re: Help with distance in square problem...

    OK ebaines, what's e^e * i^i - SIN(60)/100 - pi ?
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor ebaines's Avatar
    Joined
    Jun 2008
    From
    Illinois
    Posts
    1,051
    Thanks
    288

    Re: Help with distance in square problem...

    Quote Originally Posted by Wilmer View Post
    OK ebaines, what's e^e * i^i - SIN(60)/100 - pi ?
    Pretty cute - one answer is quite close to zero: I figure about 8.7E-6. This is if you use i^i = e^ {-\pi/2} = 0.20787... But of course i^i has multiple values - it could take on any value e^{(-\pi/2 \pm 2 k \pi)} for k = 0, 1, 2, ...
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: October 19th 2011, 02:04 AM
  2. Replies: 3
    Last Post: July 2nd 2011, 07:03 PM
  3. Distance between two random Points in a square
    Posted in the Advanced Statistics Forum
    Replies: 2
    Last Post: July 21st 2010, 09:05 AM
  4. minimising the square of a distance
    Posted in the Geometry Forum
    Replies: 3
    Last Post: July 2nd 2010, 10:00 AM
  5. Distance between points in a square
    Posted in the Geometry Forum
    Replies: 1
    Last Post: April 28th 2009, 09:47 AM

Search Tags


/mathhelpforum @mathhelpforum