Math functions

Hello,

I need some simple math functions for moving a Surface with a input like this: (float way, float angle)
I already wrote it myself. But maybe I need more such functions.
For example System.Math does not have a functions for radical. And it also misses other functions.

I could not find any other math functions besides the AgateLib.DisplayLib.Origin functions.
Has AgateLib a class for math functions?
If not could you create one in AgateLib?

Oh did not know that there

Oh did not know that there was such a function for norm, that is good.
Yes, the distance should be computed like this: Norm(a-b), looked it up wrong.

Well about the alpha function, you have two points which describe a triangle and alpha is on a.
So you get the distance and hight between a and b. Then you can compute the angle alpha.
Yes, I know this problem but forgot to add a check for it, was late yesterday and I learned vector math in half a hour.

Thanks for adding the two functions and yes this is what I was trying to get.

Hello, I wrote three methods

Hello,

I wrote three methods for the Vector2 struct:
I hope the math is correct....

  1.                 /// <summary>
  2.                 /// Computes and returns the norm of a vector.
  3.                 /// </summary>
  4.                 /// <param name="a"></param>
  5.                 /// <returns></returns>
  6.                 public static float Norm(Vector2 a)
  7.                 {
  8.                         return (float)Math.Sqrt( Math.Pow(a.X, 2) + Math.Pow(a.Y, 2) );
  9.                 }
  10.                
  11.                 /// <summary>
  12.                 /// Computes and returns the distance between to vectors.
  13.                 /// </summary>
  14.                 /// <param name="a"></param>
  15.                 /// <returns></returns>
  16.                 public static float Distance(Vector2 a, Vector2 b)
  17.                 {
  18.                         return Norm(a) - Norm(b);
  19.                 }              
  20.  
  21.                 /// <summary>
  22.                 /// Computes and returns the alpha angle from two vectors.
  23.                 /// </summary>
  24.                 /// <param name="a"></param>
  25.                 /// <param name="b"></param>
  26.                 /// <returns></returns>
  27.                 public static float Alpha(Vector2 a, Vector2 b)
  28.                 {
  29.                         return (float)Math.Asin(b.Y/Distance(a, b));
  30.                 }

There already is the function

There already is the function Vector2.Magnitude, which does the same thing as Norm except it is not static. Should your distance function be Norm(a - b)? What is the Alpha function doing? There is a bit of a problem, for example if b = (0,2) and a = (1,0), then it will take Asin(2) which is undefined.

I have added a static method which computes the distance between two vectors through this method. I also added one to calculate the angle between two vectors. I hope that is what you are trying to get at here.

There is not a general

There is not a general purpose class of math functions, analogous to System.Math in AgateLib. I've run into deficiencies in System.Math before but at the moment I can't remember what they were aside from the lack of a struct for complex numbers. What do you mean it doesn't have a function for a radical? Something like Math.Pow(x,1.0/y) gives the y-th root of x.

So that function you're talking about, it's something like

  1. PointF FromAngle(float dist, float angle)
  2. {
  3.     return new PointF(dist * Math.Cos(angle), dist * Math.Sin(angle));
  4. }

I can add something like this, probably as a static member in PointF and Vector2. Also if you give me a list of math functions that you would find useful I will work on coding them up and adding them to AgateLib. (or if you want to contribute code, that's welcome too :)

Yes, I mean this: ?4 = 2 or

Yes, I mean this: ?4 = 2 or ?81 = 3
Math.Pow(x,0.5) should work :)

Yes, this function.
Currently I don't need more math functions. Maybe later.

Edit: Seems this wiki does not like the square root char, it displays ?.