32 public static readonly
Random R =
new Random((
int)DateTime.Now.Ticks);
33 public static double Dist(
double x1,
double y1,
double x2,
double y2)
35 return Math.Sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
46 E = ((ICloneable)S).Clone() as IList;
48 throw new Exception(
"You want it copied, but it can't!");
52 for(i=0;i<E.Count-1;i++)
54 r = i+R.Next(E.Count-i);
69 Shuffle(A,
new Random((
int)DateTime.Now.Ticks),
false);
71 public static IList
Shuffle(IList A,
bool Copy)
73 return Shuffle(A,
new Random((
int)DateTime.Now.Ticks),Copy);
77 return Shuffle(A,
new Random((
int)DateTime.Now.Ticks),
true);
82 int[] E =
new int[B-A+1];
110 Array Erg = Array.CreateInstance(T,L.Count);
116 ArrayList Erg =
new ArrayList();
117 Stack CurrentBracket =
new Stack();
121 for(i=0;i<S.Length;i++)
125 CurrentBracket.Push(0);
130 CurrentBracket.Push(1);
135 CurrentBracket.Push(2);
140 if((
int)CurrentBracket.Pop()!=0)
141 throw new Exception(
"Formatfehler!");
146 if((
int)CurrentBracket.Pop()!=1)
147 throw new Exception(
"Formatfehler!");
152 if((
int)CurrentBracket.Pop()!=2)
153 throw new Exception(
"Formatfehler!");
156 if(CurrentBracket.Count>0)
158 c = Array.IndexOf(C,S[i]);
164 Erg.Add(S.Substring(Pos,i-Pos-1));
170 Erg.Add(S.Substring(Pos,i-Pos));
175 if(CurrentBracket.Count>0)
176 throw new Exception(
"Formatfehler!");
178 Erg.Add(S.Substring(Pos,i-Pos));
179 return (
string[])CopyToArray(Erg,typeof(
string));
198 public static double DASkalar(
double[] A,
double[] B)
200 if(A.Length!=B.Length)
201 throw new Exception(
"Error in Skalar!");
204 for(i=0;i<A.Length;i++)
210 public static double[]
DAMult(
double[] A,
double r)
212 double[] E =
new double[A.Length];
214 for(i=0;i<E.Length;i++)
221 public static double[]
DAAdd(
double[] A,
double[] B)
223 if(A.Length!=B.Length)
224 throw new Exception(
"Error in Skalar!");
225 double[] E=
new double[A.Length];
227 for(i=0;i<A.Length;i++)
234 public static double DADist(
double[] A,
double[] B)
236 if(A.Length!=B.Length)
237 throw new Exception(
"Unterschiedliche Längen!");
240 for(i=0;i<A.Length;i++)
241 E+=(A[i]-B[i])*(A[i]-B[i]);
245 public static double DASum(
double[] A)
248 foreach(
double D
in A)
257 return DASum(A)/(double)A.Length;
260 public static double DAStdv(
double[] A,
double M)
263 foreach(
double D
in A)
265 return Erg/(double)A.Length;
269 if (f >= 2.147484E+09f)
273 if (f <= -2.147484E+09f)
281 private static char[][] HSB_map =
new char[6][]{
new char[]{
'1',
'+',
'0'},
282 new char[]{
'-',
'1',
'0'},
283 new char[]{
'0',
'1',
'+'},
284 new char[]{
'0',
'-',
'1'},
285 new char[]{
'+',
'0',
'1'},
286 new char[]{
'1',
'0',
'-'}};
288 public static double[]
HSBtoRGB(
int hue,
int saturation,
int brightness,
double[] OldCol)
292 hue = 360 - (-hue % 360);
295 int i = (int)Math.Floor(hue/60.0),j;
297 if(OldCol==null || OldCol.Length!=3)
302 double min = 127.0 * (240.0 - saturation)/240.0;
303 double max = 255.0 - 127.0 * (240.0 - saturation)/240.0;
306 min = min + (255.0-min)*(brightness-120)/120.0;
307 max = max + (255.0-max)*(brightness-120)/120.0;
311 min = min * brightness / 120.0;
312 max = max * brightness / 120.0;
315 for (j = 0; j < 3; j++)
317 switch(HSB_map[i][j])
326 C[j] = (min + (hue % 60)/60.0 * (max - min));
329 C[j] = (max - (hue % 60)/60.0 * (max - min));
349 return Math.PI*3.0/2.0;
351 double atan = Math.Atan(y/x);
355 return 2*Math.PI+atan;
360 double dx, dy, ax, ay;
362 dx = x; ax = Math.Abs(dx);
363 dy = y; ay = Math.Abs(dy);
364 t = (ax+ay == 0) ? 0 : dy/(ax+ay);
365 if (dx < 0) t = 2-t;
else if (dy < 0) t = 4+t;
370 int dx1, dx2, dy1, dy2;
371 dx1 = P1.
X - P0.
X; dy1 = P1.
Y - P0.
Y;
372 dx2 = P2.
X - P0.
X; dy2 = P2.
Y - P0.
Y;
373 if (dx1*dy2 > dy1*dx2)
return +1;
374 if (dx1*dy2 < dy1*dx2)
return -1;
375 if ((dx1*dx2 < 0) || (dy1*dy2 < 0))
return -1;
376 if ((dx1*dx1+dy1*dy1) < (dx2*dx2+dy2*dy2) && PlusOneOnZeroDegrees)
380 public static int ccw(
double P0x,
double P0y,
double P1x,
double P1y,
double P2x,
double P2y,
bool PlusOneOnZeroDegrees)
382 double dx1, dx2, dy1, dy2;
383 dx1 = P1x - P0x; dy1 = P1y - P0y;
384 dx2 = P2x - P0x; dy2 = P2y - P0y;
385 if (dx1*dy2 > dy1*dx2)
return +1;
386 if (dx1*dy2 < dy1*dx2)
return -1;
387 if ((dx1*dx2 < 0) || (dy1*dy2 < 0))
return -1;
388 if ((dx1*dx1+dy1*dy1) < (dx2*dx2+dy2*dy2) && PlusOneOnZeroDegrees)
395 return ccw(P11, P12, P21,
true)*ccw(P11, P12, P22,
true) <= 0
396 && ccw(P21, P22, P11,
true)*ccw(P21, P22, P12,
true) <= 0;
401 double Kx = P11.
X, Ky = P11.
Y, Mx = P21.
X, My = P21.
Y;
402 double Lx = (P12.
X-P11.
X), Ly = (P12.
Y-P11.
Y), Nx = (P22.
X-P21.
X), Ny = (P22.
Y-P21.
Y);
403 double a=
double.NaN,b=
double.NaN;
407 throw new Exception(
"No intersect!");
413 throw new Exception(
"No intersect!");
419 throw new Exception(
"No intersect!");
425 throw new Exception(
"No intersect!");
430 b = (Ky + Mx*Ly/Lx - Kx*Ly/Lx - My) / (Ny - Nx*Ly/Lx);
434 return new PointF((
float)(Kx+a*Lx),(
float)(Ky+a*Ly));
438 return new PointF((
float)(Mx+b*Nx),(
float)(My+b*Ny));
440 throw new Exception(
"Error in IntersectionPoint");
static double DASkalar(double[] A, double[] B)
static string[] HighLevelSplit(string S, params char[] C)
static PointF IntersectionPoint(Point P11, Point P12, Point P21, Point P22)
static int ccw(Point P0, Point P1, Point P2, bool PlusOneOnZeroDegrees)
static double DAStdv(double[] A, double M)
static double GetAngleTheta(double x, double y)
static object[] GetArray(params object[] P)
static double[] DAAdd(double[] A, double[] B)
static double[] HSBtoRGB(int hue, int saturation, int brightness, double[] OldCol)
static int doubleToInt(double f)
static int[] GetIntArrayRange(int A, int B)
static Array CopyToArray(ICollection L, Type T)
static double DAMean(double[] A)
static void ShuffleIList(IList A)
UnityEngine.Random Random
static int[] GetIntArray(params int[] P)
static double DASum(double[] A)
static double Dist(double x1, double y1, double x2, double y2)
static bool intersect(Point P11, Point P12, Point P21, Point P22)
static int[] GetIntArrayConst(int A, int n)
static int ccw(double P0x, double P0y, double P1x, double P1y, double P2x, double P2y, bool PlusOneOnZeroDegrees)
static void ShuffleIList(IList A, Random R)
static double DADist(double[] A, double[] B)
static IList Shuffle(IList A, bool Copy)
static IList Shuffle(IList A)
static double GetAngle(double x, double y)
static double[] DAMult(double[] A, double r)
static IList Shuffle(IList S, Random R, bool Copy)