0

I want to make a side scrolling game by C# windows forms, and for that I need to make a class for two-dimensional vectors. When searching the web all I found was 3 dimensional vectors which is way beyond what I need, and as soon as I add "two dimensional" to the query I get only results for multidimensional arrays.

All I need for the class to do is to be able to get a polaric expression of a vector (size and angle) and return it's cartesic expression (X,Y) & vice-versa. I tried doing it with Math.Sin and Math.Cos but I always get weird results. Can anyone help me with an explanation or a prepared code?

Avada Kedavra
  • 8,523
  • 5
  • 32
  • 48
Elad Levy
  • 41
  • 9
  • 1
    Perhaps you're thinking `Math.Sin` and `Math.Cos` work with degrees; they actually work with radians. Otherwise it's pretty easy to roll your own `PolarCoordinate` class. I have one (with a bunch of other stuff) here that you could draw inspiration from I suppose: http://stackoverflow.com/questions/12126907/when-should-i-define-a-explicit-or-implicit-conversion-operator-in-c/12232002#12232002 – Chris Sinclair Nov 19 '12 at 18:19

1 Answers1

1

You could use Vector struct that is available in the System.Windows namespace. You can use it if you add reference to the WindowsBase.dll. Vector struct has numerous useful static methods but you can't get the angle of the Vector that simple. You could use Vector.AngleBetween for that purpose.

Nikola Davidovic
  • 8,556
  • 1
  • 27
  • 33