Created
September 10, 2020 20:17
-
-
Save kazimunshimun/e02bd43e807eb8ff2d70b1b0f97dbd77 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
private func change(location: CGPoint) { | |
// creating vector from location point | |
let vector = CGVector(dx: location.x, dy: location.y) | |
// geting angle in radian need to subtract the knob radius and padding | |
let angle = atan2(vector.dy - (config.knobRadius + 10), vector.dx - (config.knobRadius + 10)) + .pi/2.0 | |
// convert angle range from (-pi to pi) to (0 to 2pi) | |
let fixedAngle = angle < 0.0 ? angle + 2.0 * .pi : angle | |
// convert angle value to temperature value | |
let value = fixedAngle / (2.0 * .pi) * config.totalValue | |
if value >= config.minimumValue && value <= config.maximumValue { | |
temperatureValue = value | |
angleValue = fixedAngle * 180 / .pi // converting to degree | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment