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#
  4. I Need a math formula for this issue.

I Need a math formula for this issue.

Scheduled Pinned Locked Moved C#
helpgame-devquestion
4 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.
  • S Offline
    S Offline
    Silvyster
    wrote on last edited by
    #1

    I'm creating a game and I need to rotate this object. Ok i'll make my explanation simple, I have Object1 and Object2.. Let's say Object1 is at coordinates 0,0 (x,y) and Object 2 is at coordinates 10,10... Object 1 is currently facing south, Now I need object 1 to be facing Object 2 so I need the "degree" value from object 1 to object 2. Does anyone have a math formula for getting the degree? or an alternative solution can help.

    L 1 Reply Last reply
    0
    • S Silvyster

      I'm creating a game and I need to rotate this object. Ok i'll make my explanation simple, I have Object1 and Object2.. Let's say Object1 is at coordinates 0,0 (x,y) and Object 2 is at coordinates 10,10... Object 1 is currently facing south, Now I need object 1 to be facing Object 2 so I need the "degree" value from object 1 to object 2. Does anyone have a math formula for getting the degree? or an alternative solution can help.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, imagine a rectangular triangle with your two points on the hypotenuse, and the two perpendicular sides parallel to the axes. The angles you want have tangent or cotangent equal to deltaY/deltaX, so you need something similar to Math.Atan2(deltaY,deltaX). However, are you sure you need the angle? Trigonometric functions are rather expensive, and a lot of graphic stuff does not need them after all, often something much simpler can do the trick as in Math.Sqrt(deltaX*deltaX+deltaY*deltaY) for the distance, and similar stuff for projections and stuff. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Love, happiness and fewer bugs for 2009!


      L 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, imagine a rectangular triangle with your two points on the hypotenuse, and the two perpendicular sides parallel to the axes. The angles you want have tangent or cotangent equal to deltaY/deltaX, so you need something similar to Math.Atan2(deltaY,deltaX). However, are you sure you need the angle? Trigonometric functions are rather expensive, and a lot of graphic stuff does not need them after all, often something much simpler can do the trick as in Math.Sqrt(deltaX*deltaX+deltaY*deltaY) for the distance, and similar stuff for projections and stuff. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Love, happiness and fewer bugs for 2009!


        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Luc Pattyn wrote:

        imagine a rectangular triangle

        I'm trying - really I am.

        If I knew then what I know today, then I'd know the same now as I did then - then what would be the point? .\\axxx (That's an 'M')

        D 1 Reply Last reply
        0
        • L Lost User

          Luc Pattyn wrote:

          imagine a rectangular triangle

          I'm trying - really I am.

          If I knew then what I know today, then I'd know the same now as I did then - then what would be the point? .\\axxx (That's an 'M')

          D Offline
          D Offline
          Dewald
          wrote on last edited by
          #4

          :laugh:

          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