Distance between a line and a point in Objective-C ?

Posted by micropsari on Stack Overflow See other posts from Stack Overflow or by micropsari
Published on 2010-06-01T10:25:07Z Indexed on 2010/06/01 10:33 UTC
Read the original article Hit count: 180

Filed under:

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 !

© Stack Overflow or respective owner

Related posts about objective-c