Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Rotatix
- {
- long sideCount;
- int armCount;
- long[] armLengths;
- long[] armRotations;
- double[] armDegrees;
- /// Getters and setters
- ///
- public long Sides
- {
- get
- {
- return sideCount;
- }
- set
- {
- sideCount = value;
- ArmRotationsToDegrees(armRotations);
- }
- }
- public long[] Rotations
- {
- get
- {
- return armRotations;
- }
- set
- {
- armRotations = value;
- sideCount = ArmRotationsToSideCount(armRotations);
- ArmRotationsToDegrees(armRotations);
- }
- }
- public long[] Lengths
- {
- get
- {
- return armLengths;
- }
- set
- {
- armLengths = value;
- }
- }
- public int Count
- {
- get
- {
- return armCount;
- }
- set
- {
- armCount = value;
- }
- }
- public double[] Degrees
- {
- get
- {
- return armDegrees;
- }
- set
- {
- armDegrees = value;
- ArmDegreesToRotations(armDegrees);
- }
- }
- ///
- ///
- ///
- public Rotatix(int armCount)
- {
- Count = armCount;
- }
- public Rotatix(params double[] degrees)
- {
- ArmDegreesToRotations(degrees);
- }
- public Rotatix(params long[] rotations)
- {
- armCount = rotations.Length;
- armLengths = new long[armCount];
- armRotations = new long[armCount];
- armDegrees = new double[armCount];
- Array.Copy(rotations, 0, armRotations, 0, armCount);
- sideCount = ArmRotationsToSideCount(armRotations);
- ArmRotationsToDegrees(armRotations);
- }
- public void ArmRotationsToDegrees(params long[] rotations)
- {
- for (int i = 0; i < rotations.Length; ++i)
- {
- armDegrees[i] = (double)(360f / (double)((double)sideCount / (double)rotations[i]));
- //Console.WriteLine("Side Count: {0}, Degrees: {1}, Rotations: {2}", sideCount, armDegrees[i], rotations[i]);
- }
- }
- public void ArmDegreesToRotations(params double[] degrees)
- {
- List<double> _degrees = new List<double>();
- _degrees.AddRange(degrees);
- _degrees.ForEach(ParseDegrees);
- long sideCount = (long)LCM(_degrees.ToArray());
- for (int i = 0; i < degrees.Length; ++i)
- {
- armRotations[i] = (long)(sideCount / _degrees[i]);
- }
- armDegrees = degrees;
- this.sideCount = ArmRotationsToSideCount(armRotations);
- }
- public void ParseDegrees(double degree)
- {
- degree = 360 / degree;
- }
- public long ArmRotationsToSideCount(params long[] rotations)
- {
- long lcm = (long)LCM(rotations);
- return lcm;
- }
- public double GCD(double a, double b)
- {
- while (b != 0)
- {
- double x = b;
- b = a % b;
- a = x;
- }
- return a;
- }
- public double _LCM(double a, double b)
- {
- return a * b / GCD(a, b);
- }
- public long GCD(long a, long b)
- {
- while (b != 0)
- {
- long x = b;
- b = a % b;
- a = x;
- }
- return a;
- }
- public long _LCM(long a, long b)
- {
- return a * b / GCD(a, b);
- }
- public long LCM(params long[] integers)
- {
- long[] integers2 = new long[integers.Length - 1];
- if (integers.Length >= 2)
- {
- integers2[0] = _LCM(integers[0], integers[1]);
- if (integers.Length >= 3)
- {
- Array.Copy(integers, 2, integers2, 1, integers2.Length - 1);
- }
- return LCM(integers2);
- }
- else
- {
- return integers[0];
- }
- }
- public double LCM(params double[] integers)
- {
- double[] integers2 = new double[integers.Length - 1];
- if (integers.Length >= 2)
- {
- integers2[0] = _LCM(integers[0], integers[1]);
- if (integers.Length >= 3)
- {
- Array.Copy(integers, 2, integers2, 1, integers2.Length - 1);
- }
- return LCM(integers2);
- }
- else
- {
- return integers[0];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement