Hello,
I have 2 class :
// point : (x, y)
@interface ICPoint : NSObject {
NSInteger x;
NSInteger y;
}
// line : y= ax + b
@interface ICLine : NSObject {
float a;
float b;
}
and this method:
// return the distance between a line and a point
-(NSInteger) distance:(ICPoint *)point {
return fabs(-a*point.x +point.y - b) / sqrt(a*a + 1);
}
The formula seems right (based on wikipedia), but the results are wrong... why ?
Thanks !
Edit:
ICLine *line1 = [[ICLine alloc] initWithA:0.60 andB:11.25];
ICLine *line2 = [[ICLine alloc] initWithA:0.61 andB:-2.85];
ICPoint *point = [[ICPoint alloc] initWithX:41 andY:22];
[line1 distance:point]; // give 11, it's ok.
[line2 distance:point]; // give 24, it should be ~0...