Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Math expression does not return what I expected.

    General and Desktop
    2
    2
    414
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ealione
      ealione last edited by

      I wanted to track the x,y coordinates of the tip of the second's clock hand.

      That clock hand has a length of 30 so I just did

      @ int posx = cos(360 * (time.second() / 60.0)) * 30 + 0;
      int posy = sin(360 * (time.second() / 60.0)) * 30 + 0;

      qDebug() << "second: " + time.toString("ss");
      qDebug() << "angle: " + QString::number(360 * (time.second() / 60.0));    
      qDebug() << "x:" + QString::number(posx)+"y:" + QString::number(posy);@
      

      Now what I would expect is for values such as when the seconds are 0, 15, 30, 45, 60 the angles to be

      0, 90, 180, 270, 0 and the positions of curse
      @x:0, y:30,
      x:30, y:0,
      x:0, y:-30,
      x:-30, y:0,
      x:0, y:30@

      Yet this is not what I get from the piece of code posted above. instead some values are
      @"angle: 60"
      "x:-28y:-9"
      "second: 11"
      "angle: 66"
      "x:-29y:0"
      "second: 12"
      "angle: 72"
      "x:-29y:7"
      "second: 13"
      "angle: 78"
      "x:-25y:15"
      "second: 14"
      "angle: 84"
      "x:-20y:21"
      "second: 15"
      "angle: 90"
      "x:-13y:26"
      "second: 16"
      "angle: 96"
      "x:-5y:29"@

      What am I doing wrong here?

      EDIT
      just after pressing post for this question it came to me that there might be a slight possibility Qt's sin, and cos expressions use rads instead of degrees. That fixed the issue.

      1 Reply Last reply Reply Quote 0
      • S
        SysTech last edited by

        Ya I was going to say most sin/cos implementations are radians.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post