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