// // MyPoint.m // B-spline // // Created by Alexander Powell on Tue Aug 27 2002. // Copyright (c) 2002 __MyCompanyName__. All rights reserved. // #import "MyPoint.h" @implementation MyPoint - (id)init { return [self initWithX: 0.0f y: 0.0f z: 0.0f]; } - (id)initWithX:(double)newX y:(double)newY z:(double)newZ { if (self = [super init]) { x = newX; y = newY; z = newZ; return self; } return nil; } - (void)negate { x = -x; y = -y; z = -z; } - (void)normalize { double length; // Calculate The Length Of The Vector length = (double)sqrt((x*x) + (y*y) + (z*z)); if(length == 0.0f) // Prevents Divide By 0 Error length = 1.0f; x /= length; y /= length; z /= length; } - (double)x { return x; } - (double)y { return y; } - (double)z { return z; } - (void)setX:(double)newX { x = newX; } - (void)setY:(double)newY { y = newY; } - (void)setZ:(double)newZ { z = newZ; } - (NSString *)description { return [NSString stringWithFormat: @"(%f, %f, %f)", x, y, z]; } @end