obj-c how to use normalizedPoints
时间: 2023-12-22 13:02:22 浏览: 32
In Objective-C, `normalizedPoints` typically refers to an array of `CGPoint` values normalized to a specific coordinate system.
To use `normalizedPoints`, you can define an array of `CGPoint` values and normalize them using a specific coordinate system. For example, if you want to normalize the points to a coordinate system with the origin at the center of the screen, you can use the following code:
```
NSMutableArray *normalizedPoints = [NSMutableArray array];
for (NSValue *pointValue in pointsArray) {
CGPoint point = [pointValue CGPointValue];
CGFloat x = (point.x - CGRectGetMidX(self.view.bounds)) / CGRectGetWidth(self.view.bounds);
CGFloat y = (point.y - CGRectGetMidY(self.view.bounds)) / CGRectGetHeight(self.view.bounds);
[normalizedPoints addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
}
```
In this example, `pointsArray` is an array of `NSValue` objects that contain `CGPoint` values. The code loops through each point, subtracts the center of the screen from its x and y values, and then divides by the width and height of the screen to normalize the point to a range between -1 and 1. The normalized point is then added to the `normalizedPoints` array as an `NSValue` object.
Keep in mind that the specific way you normalize the points may depend on the requirements of your application or algorithm.