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

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,r,0};
double [] y={r,r,0};
double [] z={r,r,0};
double [] omega={0,0,0};
double [] i={0,0,0};
double alpha_t = r*(-r) - r*(-r) - r*(-r);
double [] alpha={r,r,r,alpha_t};
omega=alpha*x+alpha*y+alpha*z;
omega=alpha*x+alpha*y+alpha*z-alpha;
omega=-omega/omega;
i=x+x*omega;
i=y+y*omega;
i=z+z*omega;
double dist_=Math.pow((P-i), 2)+Math.pow((P-i), 2)+Math.pow((P-i), 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.  Reply With Quote

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?  Reply With Quote

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.  Reply With Quote

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  Reply With Quote

distance, line, math, point 