-
-
Save hsavit1/6ed9779475f36bfdd230 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func projectFunctionToCoordinateSystem(function f: FunctionType) -> (p0: CGPoint, p1: CGPoint) -> (x: CGFloat) -> CGPoint { | |
return { p0, p1 in | |
return { x in | |
let (dx, dy) = (p1.x - p0.x, p1.y - p0.y) | |
let (magnitude, theta) = (hypot(dy, dx), atan2(dy, dx)) // Thanks loooop | |
var outPoint = CGPoint(x: x * magnitude, y: f(x) * magnitude) | |
outPoint = CGPointApplyAffineTransform(outPoint, CGAffineTransformMakeRotation(theta)) | |
outPoint = CGPointApplyAffineTransform(outPoint, CGAffineTransformMakeTranslation(p0.x, p0.y)) | |
return CGPoint(x: outPoint.x, y: outPoint.y) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment