Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Math expression does not return what I expected.
QtWS25 Last Chance

Math expression does not return what I expected.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 530 Views
  • 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SysTech
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved