-1

I do not know what I did wrong in this code:

func findDegree() -> Double {
    let xValue = directionstick.center.x - 35
    let yValue = directionstick.center.y + 20
    let newX = xValue*xValue
    let newY = yValue*yValue
    let hypo = (newX+newY).squareRoot()
    return (xValue/hypo)

}

This code is for finding the amount of rotation.

John Song
  • 3
  • 3
  • Hi and welcome to SO! Your question is a little unclear. Can you provide more context and preferrably more code? Rotation of what? And in relation to what? What is `directionstick`? A complete example with reproducible results would be best. – Losiowaty Dec 04 '18 at 00:38
  • Really it should be a code that could rotate anything. For example rect.rotate(FindDegree()) – John Song Dec 04 '18 at 13:00

1 Answers1

0

I figured it out:

func findDegree() -> Double {
    let xValue = directionstick.center.x - 35
    let yValue = directionstick.center.y + 20
    let angle = atan2(xValue, yValue)
    Return angle
}
John Song
  • 3
  • 3