Results 1 to 4 of 4
  1. #1
    branquinho is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Unhappy Distance between a point and a rect

    Hi guys. I need your help. I've a project to school that I need to find the distance between a point and a line without using the distance formula in R3.

    I already have this:
    Java Code:
    public static void main(String[] args){
            int[] eq = {1,0,2,2,-1,-3};    //data from equation (x,y,z)=(x0,y0,z0)+k(a,b,c)     eq={x0,y0,z0,a,b,c}
            int[] P = {1,-1,2};              //point
            distance(P,eq);
            }
    
    public static void distance(int[] P, int[] r){
            double [] x={r[0],r[3],0};
            double [] y={r[1],r[4],0};
            double [] z={r[2],r[5],0};
            double [] omega={0,0,0};
            double [] i={0,0,0};
            double alpha_t = r[3]*(-r[0]) - r[4]*(-r[1]) - r[5]*(-r[2]);
            double [] alpha={r[3],r[4],r[5],alpha_t};
            omega[0]=alpha[0]*x[1]+alpha[1]*y[1]+alpha[2]*z[1];
            omega[1]=alpha[0]*x[0]+alpha[1]*y[0]+alpha[2]*z[0]-alpha[3];
            omega[2]=-omega[1]/omega[0];
            i[0]=x[0]+x[1]*omega[2];
            i[1]=y[0]+y[1]*omega[2];
            i[2]=z[0]+z[1]*omega[2];
            double dist_=Math.pow((P[0]-i[0]), 2)+Math.pow((P[1]-i[1]), 2)+Math.pow((P[2]-i[2]), 2);
            double dist=Math.sqrt(dist_);
            System.out.println(dist);
        }
    This code works with some numbers, but not always...
    If someone could help me, I would be grateful.
    Last edited by branquinho; 01-03-2012 at 07:20 PM.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Distance between a point and a rect

    Ok, first off, could you modify your post to put the code inside [code][/code] tags so we can read it?

  3. #3
    branquinho is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Distance between a point and a rect

    Quote Originally Posted by quad64bit View Post
    Ok, first off, could you modify your post to put the code inside [code][/code] tags so we can read it?
    Sorry, fixed.

  4. #4
    branquinho is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Distance between a point and a rect

    already finished the programm. thanks anyway

Similar Threads

  1. Replies: 4
    Last Post: 10-17-2011, 09:09 PM
  2. Replies: 0
    Last Post: 10-15-2011, 11:56 PM
  3. MouseEntered to rect
    By g6pd in forum New To Java
    Replies: 3
    Last Post: 03-10-2011, 02:52 PM
  4. Replies: 0
    Last Post: 04-02-2009, 10:00 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •