# Thread: Distance between a point and a rect

1. Member
Join Date
Jan 2012
Posts
3
Rep Power
0

## 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 06:20 PM.

2. ## 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. Member
Join Date
Jan 2012
Posts
3
Rep Power
0

## Re: Distance between a point and a rect

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

4. Member
Join Date
Jan 2012
Posts
3
Rep Power
0

## Re: Distance between a point and a rect

already finished the programm. thanks anyway

#### Posting Permissions

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