Announcement

Collapse
No announcement yet.

Help with math to code conversion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with math to code conversion



    So, my team is attempting to incorporate some advanced math into their Android Studio code and they have run into a bit of a wall that they are hopeful someone can help with.

    Basically, they are trying to make their robot drive in an arc and need to rotate a parabola to do so. They have the formula and understand the math and how to apply it, but cant put it in the code (y*cosθ - x*sinθ = f(y*sinθ + x*cosθ). Long story short we need an algebra, trig, or linear algebra java library or some way to use math in the code. Specifically we need a way to solve for variables in this case, but the ability to do lots of math would be much more useful. Any help would be greatly appreciated!

  • #2
    What's wrong with Math.sin(Math.toRadians(degrees)) and Math.cos(Math.toRadians(degrees))?

    Comment


    • #3
      Originally posted by 4634 Programmer View Post
      What's wrong with Math.sin(Math.toRadians(degrees)) and Math.cos(Math.toRadians(degrees))?
      Seriously 4634 Programmer ? GladiatorsCoach came here with a very specific question, and gave plenty of detail, and your response is to be snarky because they may not know the code as well as you?

      We know you do a lot to help teams, and you've probably helped us, but when someone comes here for help, especially a fairly new team, there's no reason to hit them over the head with how much smarter you are. Not cool at all, and certainly not Graciously Profesional.

      Michael Clark
      Lead Mentor
      Redfish Robotics

      Michael P Clark
      Founding Mentor, FTC 9958
      http://www.redfishrobotics.com
      "We're Hooked on FIRST"

      Comment


      • #4
        Originally posted by RedfishRobotics View Post

        Seriously 4634 Programmer ? GladiatorsCoach came here with a very specific question, and gave plenty of detail, and your response is to be snarky because they may not know the code as well as you?

        We know you do a lot to help teams, and you've probably helped us, but when someone comes here for help, especially a fairly new team, there's no reason to hit them over the head with how much smarter you are. Not cool at all, and certainly not Graciously Profesional.

        Michael Clark
        Lead Mentor
        Redfish Robotics
        I certainly wasn't trying to be snarky..... maybe I'm missing something here, but it seemed like the sin/cos functions were all that was missing to implement the function?

        Comment


        • #5
          Originally posted by 4634 Programmer View Post

          I certainly wasn't trying to be snarky..... maybe I'm missing something here, but it seemed like the sin/cos functions were all that was missing to implement the function?
          4634 Programmer Maybe my misreading, apologies.
          Michael P Clark
          Founding Mentor, FTC 9958
          http://www.redfishrobotics.com
          "We're Hooked on FIRST"

          Comment


          • #6
            Originally posted by RedfishRobotics View Post

            4634 Programmer Maybe my misreading, apologies.
            No hard feelings. But at any rate - unless I'm missing something - all that has to be done is to solve for the variable in question on a piece of paper, and plug that formula into a method, using Math.sin() and Math.cos()

            Comment


            • #7
              Originally posted by 4634 Programmer View Post

              No hard feelings. But at any rate - unless I'm missing something - all that has to be done is to solve for the variable in question on a piece of paper, and plug that formula into a method, using Math.sin() and Math.cos()
              Thanks (again), and for clarity, I don't know the coding in question well enough to know if your solution is correct, but I don't have any reason to believe it wouldn't work.
              Michael P Clark
              Founding Mentor, FTC 9958
              http://www.redfishrobotics.com
              "We're Hooked on FIRST"

              Comment


              • #8
                Assuming that x, y, and theta are variables, you can use
                Code:
                import static java.lang.Math.sin;
                import static java.lang.Math.cos;
                . I use static import so I can just do sin() instead of Math.sin().
                ​​​​​The java.lang.Math library is what you need in general for this stuff, it contains all the different trig and math functions and constants such as PI.

                Comment

                Working...
                X