Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. inverse sinus, floats

inverse sinus, floats

Scheduled Pinned Locked Moved C / C++ / MFC
c++
15 Posts 4 Posters 0 Views 1 Watching
  • 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.
  • L Lost User

    It's all in the documentation: Format Specification Syntax: printf and wprintf Functions | Microsoft Docs[^].

    C Offline
    C Offline
    Calin Negru
    wrote on last edited by
    #3

    found it thanks

    1 Reply Last reply
    0
    • C Calin Negru

      I have a tough time finding the inverse sinus math function in c++. There is asinf() but I`m not sure about what it does. [fixed] Displaying a float in StringCchPrintfA

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #4

      The documentation of asin should be just enoough:

      '(it) Computes the principal value of the arc sine of arg'

      That is you get the first quadrant angle correnspondig to the sin value passed as argument. The following program

      #include #include using namespace std;

      int main()
      {
      const size_t N = 18;
      const double delta = M_PI/N;

      for ( double phi = 0; phi < 2*M_PI; phi += delta)
      {
      double s = sin(phi);
      double a = asin(s);
      cout << "phi = " << phi << ", sin(phi) = " << s << ", asin(sin(phi)) = " << a << "\n";
      }
      cout << endl;
      }

      outputs

      phi = 0, sin(phi) = 0, asin(sin(phi)) = 0
      phi = 0.174533, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
      phi = 0.349066, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
      phi = 0.523599, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
      phi = 0.698132, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
      phi = 0.872665, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
      phi = 1.0472, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
      phi = 1.22173, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
      phi = 1.39626, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
      phi = 1.5708, sin(phi) = 1, asin(sin(phi)) = 1.5708
      phi = 1.74533, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
      phi = 1.91986, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
      phi = 2.0944, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
      phi = 2.26893, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
      phi = 2.44346, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
      phi = 2.61799, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
      phi = 2.79253, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
      phi = 2.96706, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
      phi = 3.14159, sin(phi) = 1.45473e-15, asin(sin(phi)) = 1.45473e-15
      phi = 3.31613, sin(phi) = -0.173648, asin(sin(phi)) = -0.174533
      phi = 3.49066, sin(phi) = -0.34202, asin(sin(phi)) = -0.349066
      phi = 3.66519, sin(phi) = -0.5, asin(sin(phi)) = -0.523599
      phi = 3.83972, sin(phi) = -0.642788, asin(sin(phi)) = -0.698132
      phi = 4.01426, sin(phi) = -0.766044, asin(sin(phi)) = -0.872665
      phi = 4.18879, sin(phi) = -0.866025, asin(sin(phi)) = -1.0472
      phi = 4.36332, sin(phi) = -0.939693, asin(sin(phi)) = -1.22173
      phi = 4.53786, sin(phi) = -0.984808, asin(sin(phi)) = -1.39626
      phi = 4.71239, sin(phi) = -1, asin(sin(phi)) = -1.5708
      phi = 4.88692, sin(phi) = -0.984808, asin(sin(phi)) = -1.39626
      phi = 5.06145, sin(phi) = -0.939693, asin(sin(phi)) = -1.22173
      phi = 5

      In testa che avete, signor di Ceprano?

      C 2 Replies Last reply
      0
      • CPalliniC CPallini

        The documentation of asin should be just enoough:

        '(it) Computes the principal value of the arc sine of arg'

        That is you get the first quadrant angle correnspondig to the sin value passed as argument. The following program

        #include #include using namespace std;

        int main()
        {
        const size_t N = 18;
        const double delta = M_PI/N;

        for ( double phi = 0; phi < 2*M_PI; phi += delta)
        {
        double s = sin(phi);
        double a = asin(s);
        cout << "phi = " << phi << ", sin(phi) = " << s << ", asin(sin(phi)) = " << a << "\n";
        }
        cout << endl;
        }

        outputs

        phi = 0, sin(phi) = 0, asin(sin(phi)) = 0
        phi = 0.174533, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
        phi = 0.349066, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
        phi = 0.523599, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
        phi = 0.698132, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
        phi = 0.872665, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
        phi = 1.0472, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
        phi = 1.22173, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
        phi = 1.39626, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
        phi = 1.5708, sin(phi) = 1, asin(sin(phi)) = 1.5708
        phi = 1.74533, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
        phi = 1.91986, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
        phi = 2.0944, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
        phi = 2.26893, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
        phi = 2.44346, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
        phi = 2.61799, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
        phi = 2.79253, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
        phi = 2.96706, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
        phi = 3.14159, sin(phi) = 1.45473e-15, asin(sin(phi)) = 1.45473e-15
        phi = 3.31613, sin(phi) = -0.173648, asin(sin(phi)) = -0.174533
        phi = 3.49066, sin(phi) = -0.34202, asin(sin(phi)) = -0.349066
        phi = 3.66519, sin(phi) = -0.5, asin(sin(phi)) = -0.523599
        phi = 3.83972, sin(phi) = -0.642788, asin(sin(phi)) = -0.698132
        phi = 4.01426, sin(phi) = -0.766044, asin(sin(phi)) = -0.872665
        phi = 4.18879, sin(phi) = -0.866025, asin(sin(phi)) = -1.0472
        phi = 4.36332, sin(phi) = -0.939693, asin(sin(phi)) = -1.22173
        phi = 4.53786, sin(phi) = -0.984808, asin(sin(phi)) = -1.39626
        phi = 4.71239, sin(phi) = -1, asin(sin(phi)) = -1.5708
        phi = 4.88692, sin(phi) = -0.984808, asin(sin(phi)) = -1.39626
        phi = 5.06145, sin(phi) = -0.939693, asin(sin(phi)) = -1.22173
        phi = 5

        C Offline
        C Offline
        Calin Negru
        wrote on last edited by
        #5

        I`m doing something wrong. In a right triangle the hypotenuse length is 80.62 the triangle side length opposing the angle is 40. The windows calculator result for inverse sin 40/80.6225 is 29.74 When I do the math with asinf() I`m getting 0.519

        CPalliniC V 2 Replies Last reply
        0
        • C Calin Negru

          I`m doing something wrong. In a right triangle the hypotenuse length is 80.62 the triangle side length opposing the angle is 40. The windows calculator result for inverse sin 40/80.6225 is 29.74 When I do the math with asinf() I`m getting 0.519

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #6

          Post your code, then. The following program

          #include
          #include
          using namespace std;

          int main()
          {
          double angle = asin( 40/80.6225 );
          cout << "angle " << angle << " (" << (angle * 180 / M_PI) << " degrees)" << endl;
          }

          Outputs

          angle 0.519147 (29.7449 degrees)

          In testa che avete, signor di Ceprano?

          C 1 Reply Last reply
          0
          • CPalliniC CPallini

            Post your code, then. The following program

            #include
            #include
            using namespace std;

            int main()
            {
            double angle = asin( 40/80.6225 );
            cout << "angle " << angle << " (" << (angle * 180 / M_PI) << " degrees)" << endl;
            }

            Outputs

            angle 0.519147 (29.7449 degrees)

            C Offline
            C Offline
            Calin Negru
            wrote on last edited by
            #7

            after conversion the result is as it should be , thanks

            CPalliniC 1 Reply Last reply
            0
            • C Calin Negru

              I`m doing something wrong. In a right triangle the hypotenuse length is 80.62 the triangle side length opposing the angle is 40. The windows calculator result for inverse sin 40/80.6225 is 29.74 When I do the math with asinf() I`m getting 0.519

              V Offline
              V Offline
              Victor Nijegorodov
              wrote on last edited by
              #8

              You probably mix degrees with radians.

              C 1 Reply Last reply
              0
              • V Victor Nijegorodov

                You probably mix degrees with radians.

                C Offline
                C Offline
                Calin Negru
                wrote on last edited by
                #9

                Math is tricky

                1 Reply Last reply
                0
                • C Calin Negru

                  after conversion the result is as it should be , thanks

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #10

                  You are welcome.

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    The documentation of asin should be just enoough:

                    '(it) Computes the principal value of the arc sine of arg'

                    That is you get the first quadrant angle correnspondig to the sin value passed as argument. The following program

                    #include #include using namespace std;

                    int main()
                    {
                    const size_t N = 18;
                    const double delta = M_PI/N;

                    for ( double phi = 0; phi < 2*M_PI; phi += delta)
                    {
                    double s = sin(phi);
                    double a = asin(s);
                    cout << "phi = " << phi << ", sin(phi) = " << s << ", asin(sin(phi)) = " << a << "\n";
                    }
                    cout << endl;
                    }

                    outputs

                    phi = 0, sin(phi) = 0, asin(sin(phi)) = 0
                    phi = 0.174533, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
                    phi = 0.349066, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
                    phi = 0.523599, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
                    phi = 0.698132, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
                    phi = 0.872665, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
                    phi = 1.0472, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
                    phi = 1.22173, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
                    phi = 1.39626, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
                    phi = 1.5708, sin(phi) = 1, asin(sin(phi)) = 1.5708
                    phi = 1.74533, sin(phi) = 0.984808, asin(sin(phi)) = 1.39626
                    phi = 1.91986, sin(phi) = 0.939693, asin(sin(phi)) = 1.22173
                    phi = 2.0944, sin(phi) = 0.866025, asin(sin(phi)) = 1.0472
                    phi = 2.26893, sin(phi) = 0.766044, asin(sin(phi)) = 0.872665
                    phi = 2.44346, sin(phi) = 0.642788, asin(sin(phi)) = 0.698132
                    phi = 2.61799, sin(phi) = 0.5, asin(sin(phi)) = 0.523599
                    phi = 2.79253, sin(phi) = 0.34202, asin(sin(phi)) = 0.349066
                    phi = 2.96706, sin(phi) = 0.173648, asin(sin(phi)) = 0.174533
                    phi = 3.14159, sin(phi) = 1.45473e-15, asin(sin(phi)) = 1.45473e-15
                    phi = 3.31613, sin(phi) = -0.173648, asin(sin(phi)) = -0.174533
                    phi = 3.49066, sin(phi) = -0.34202, asin(sin(phi)) = -0.349066
                    phi = 3.66519, sin(phi) = -0.5, asin(sin(phi)) = -0.523599
                    phi = 3.83972, sin(phi) = -0.642788, asin(sin(phi)) = -0.698132
                    phi = 4.01426, sin(phi) = -0.766044, asin(sin(phi)) = -0.872665
                    phi = 4.18879, sin(phi) = -0.866025, asin(sin(phi)) = -1.0472
                    phi = 4.36332, sin(phi) = -0.939693, asin(sin(phi)) = -1.22173
                    phi = 4.53786, sin(phi) = -0.984808, asin(sin(phi)) = -1.39626
                    phi = 4.71239, sin(phi) = -1, asin(sin(phi)) = -1.5708
                    phi = 4.88692, sin(phi) = -0.984808, asin(sin(phi)) = -1.39626
                    phi = 5.06145, sin(phi) = -0.939693, asin(sin(phi)) = -1.22173
                    phi = 5

                    C Offline
                    C Offline
                    Calin Negru
                    wrote on last edited by
                    #11

                    I`m working on several things at the same time. Don`t go wandering if I`m active simultaneously in two threads.

                    Quote:

                    That is you get the first quadrant angle correnspondig to the sin value passed as argument.

                    What`s the formula when you want work with remaining quadrants? This formula doesn`t work always.

                    CPalliniC 1 Reply Last reply
                    0
                    • C Calin Negru

                      I`m working on several things at the same time. Don`t go wandering if I`m active simultaneously in two threads.

                      Quote:

                      That is you get the first quadrant angle correnspondig to the sin value passed as argument.

                      What`s the formula when you want work with remaining quadrants? This formula doesn`t work always.

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #12

                      You have to use the atan2[^] function.

                      In testa che avete, signor di Ceprano?

                      C 1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        You have to use the atan2[^] function.

                        C Offline
                        C Offline
                        Calin Negru
                        wrote on last edited by
                        #13

                        Thanks CPallini

                        CPalliniC 1 Reply Last reply
                        0
                        • C Calin Negru

                          Thanks CPallini

                          CPalliniC Offline
                          CPalliniC Offline
                          CPallini
                          wrote on last edited by
                          #14

                          You are welcome.

                          In testa che avete, signor di Ceprano?

                          1 Reply Last reply
                          0
                          • C Calin Negru

                            I have a tough time finding the inverse sinus math function in c++. There is asinf() but I`m not sure about what it does. [fixed] Displaying a float in StringCchPrintfA

                            C Offline
                            C Offline
                            Calin Negru
                            wrote on last edited by
                            #15

                            I have my object rotation algorithm working though it will only rotate 180 degrees atm. It`s an algorithm that handles object rotations without matrices.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups