Some math for the first time!

I've never had to use more than arithmetic in before, but today I had to use arc cosine for the first time.
I'm drawing a line that from point A to point B, and below is the equation I had to use. Awesome stuff.


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.view];
float deltaX2 = originalPoint.x - currentTouchPosition.x;
float deltaY2 = fabsf(originalPoint.y - currentTouchPosition.y);
float c = sqrt( pow(deltaY2,2) + pow(deltaX2,2));
float radian = acos( (deltaX2 / c ) );
if(originalPoint.y < currentTouchPosition.y) radian = -radian;
CGAffineTransform transformRadian = CGAffineTransformMakeRotation(radian);
theSlash.transform = transformRadian;


No comments:

Post a Comment