public static Vector2 FromLookAt(Vector3 dir) => new Vector2(-MathF.Asin(-dir.Y), MathF.Atan2(dir.X, dir.Z));
public override RacketNumber Evaluate() { RacketNumber currentNumber = (RacketNumber)arguments[0].Evaluate(); return(RacketNumber.Parse(MathF.Asin(currentNumber.Value), false, currentNumber.IsRational)); }
public void AsinTest() { AssumeFunctionSupported("asin"); Test(o => MathF.Round(MathF.Asin((float)o.Discount), 5)); }
private Dictionary <string, Mesh> GenerateMeshes(Table.Table table) { var meshes = new Dictionary <string, Mesh>(); var fullMatrix = new Matrix3D(); fullMatrix.RotateZMatrix(MathF.DegToRad(180.0f)); var height = table.GetSurfaceHeight(_data.Surface, _data.Center.X, _data.Center.Y); var baseRadius = _data.BaseRadius - _data.RubberThickness; var endRadius = _data.EndRadius - _data.RubberThickness; // calc angle needed to fix P0 location var sinAngle = (baseRadius - endRadius) / _data.FlipperRadius; if (sinAngle > 1.0) { sinAngle = 1.0f; } if (sinAngle < -1.0) { sinAngle = -1.0f; } var fixAngle = MathF.Asin(sinAngle); var fixAngleScale = fixAngle / (float)(System.Math.PI * 0.5); // scale (in relation to 90 deg.) // fixAngleScale = 0.0; // note: if you force fixAngleScale = 0.0 then all will look as old version // lambda used to apply fix void ApplyFix(ref Vertex3DNoTex2 vert, Vertex2D center, float midAngle, float radius, Vertex2D newCenter) { var vAngle = MathF.Atan2(vert.Y - center.Y, vert.X - center.X); var nAngle = MathF.Atan2(vert.Ny, vert.Nx); // we want have angles with same sign as midAngle, fix it: if (midAngle < 0.0) { if (vAngle > 0.0) { vAngle -= (float)(System.Math.PI * 2.0); } if (nAngle > 0.0) { nAngle -= (float)(System.Math.PI * 2.0); } } else { if (vAngle < 0.0) { vAngle += (float)(System.Math.PI * 2.0); } if (nAngle < 0.0) { nAngle += (float)(System.Math.PI * 2.0); } } nAngle -= (vAngle - midAngle) * fixAngleScale * MathF.Sign(midAngle); vAngle -= (vAngle - midAngle) * fixAngleScale * MathF.Sign(midAngle); float nL = new Vertex2D(vert.Nx, vert.Ny).Length(); vert.X = MathF.Cos(vAngle) * radius + newCenter.X; vert.Y = MathF.Sin(vAngle) * radius + newCenter.Y; vert.Nx = MathF.Cos(nAngle) * nL; vert.Ny = MathF.Sin(nAngle) * nL; } // base and tip var baseMesh = FlipperBaseMesh.Clone(Base); for (var t = 0; t < 13; t++) { for (var i = 0; i < baseMesh.Vertices.Length; i++) { var v = baseMesh.Vertices[i]; if (v.X == VertsBaseBottom[t].X && v.Y == VertsBaseBottom[t].Y && v.Z == VertsBaseBottom[t].Z) { ApplyFix(ref baseMesh.Vertices[i], new Vertex2D(VertsBaseBottom[6].X, VertsBaseBottom[0].Y), (float)-(System.Math.PI * 0.5), baseRadius, new Vertex2D(0, 0)); } if (v.X == VertsTipBottom[t].X && v.Y == VertsTipBottom[t].Y && v.Z == VertsTipBottom[t].Z) { ApplyFix(ref baseMesh.Vertices[i], new Vertex2D(VertsTipBottom[6].X, VertsTipBottom[0].Y), (float)(System.Math.PI * 0.5), endRadius, new Vertex2D(0, _data.FlipperRadius)); } if (v.X == VertsBaseTop[t].X && v.Y == VertsBaseTop[t].Y && v.Z == VertsBaseTop[t].Z) { ApplyFix(ref baseMesh.Vertices[i], new Vertex2D(VertsBaseBottom[6].X, VertsBaseBottom[0].Y), (float)(-System.Math.PI * 0.5), baseRadius, new Vertex2D(0, 0)); } if (v.X == VertsTipTop[t].X && v.Y == VertsTipTop[t].Y && v.Z == VertsTipTop[t].Z) { ApplyFix(ref baseMesh.Vertices[i], new Vertex2D(VertsTipBottom[6].X, VertsTipBottom[0].Y), (float)(System.Math.PI * 0.5), endRadius, new Vertex2D(0, _data.FlipperRadius)); } } } baseMesh.Transform(fullMatrix, null, z => z * _data.Height * table.GetScaleZ() + height); meshes[Base] = baseMesh; // rubber if (_data.RubberThickness > 0.0) { var rubberMesh = FlipperBaseMesh.Clone(Rubber); for (var t = 0; t < 13; t++) { for (var i = 0; i < rubberMesh.Vertices.Length; i++) { var v = rubberMesh.Vertices[i]; if (v.X == VertsBaseBottom[t].X && v.Y == VertsBaseBottom[t].Y && v.Z == VertsBaseBottom[t].Z) { ApplyFix(ref rubberMesh.Vertices[i], new Vertex2D(VertsBaseBottom[6].X, VertsBaseBottom[0].Y), (float)(-System.Math.PI * 0.5), baseRadius + _data.RubberThickness, new Vertex2D(0, 0)); } if (v.X == VertsTipBottom[t].X && v.Y == VertsTipBottom[t].Y && v.Z == VertsTipBottom[t].Z) { ApplyFix(ref rubberMesh.Vertices[i], new Vertex2D(VertsTipBottom[6].X, VertsTipBottom[0].Y), (float)(System.Math.PI * 0.5), endRadius + _data.RubberThickness, new Vertex2D(0, _data.FlipperRadius)); } if (v.X == VertsBaseTop[t].X && v.Y == VertsBaseTop[t].Y && v.Z == VertsBaseTop[t].Z) { ApplyFix(ref rubberMesh.Vertices[i], new Vertex2D(VertsBaseBottom[6].X, VertsBaseBottom[0].Y), (float)(-System.Math.PI * 0.5), baseRadius + _data.RubberThickness, new Vertex2D(0, 0)); } if (v.X == VertsTipTop[t].X && v.Y == VertsTipTop[t].Y && v.Z == VertsTipTop[t].Z) { ApplyFix(ref rubberMesh.Vertices[i], new Vertex2D(VertsTipBottom[6].X, VertsTipBottom[0].Y), (float)(System.Math.PI * 0.5), endRadius + _data.RubberThickness, new Vertex2D(0, _data.FlipperRadius)); } } } rubberMesh.Transform(fullMatrix, null, z => z * _data.RubberWidth * table.GetScaleZ() + (height + _data.RubberHeight)); meshes[Rubber] = rubberMesh; } return(meshes); }
public override void ReceiveSignal(Signal signal, Connection connection) { float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float value); switch (Function) { case FunctionType.Sin: if (!UseRadians) { value = MathHelper.ToRadians(value); } value = MathF.Sin(value); break; case FunctionType.Cos: if (!UseRadians) { value = MathHelper.ToRadians(value); } value = MathF.Cos(value); break; case FunctionType.Tan: if (!UseRadians) { value = MathHelper.ToRadians(value); } //tan is undefined if the value is (π / 2) + πk, where k is any integer if (!MathUtils.NearlyEqual(value % MathHelper.Pi, MathHelper.PiOver2)) { value = MathF.Tan(value); } break; case FunctionType.Asin: //asin is only defined in the range [-1,1] if (value >= -1.0f && value <= 1.0f) { float angle = MathF.Asin(value); if (!UseRadians) { angle = MathHelper.ToDegrees(angle); } value = angle; } break; case FunctionType.Acos: //acos is only defined in the range [-1,1] if (value >= -1.0f && value <= 1.0f) { float angle = MathF.Acos(value); if (!UseRadians) { angle = MathHelper.ToDegrees(angle); } value = angle; } break; case FunctionType.Atan: if (connection.Name == "signal_in_x") { timeSinceReceived[0] = 0.0f; float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]); } else if (connection.Name == "signal_in_y") { timeSinceReceived[1] = 0.0f; float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]); } else { float angle = MathF.Atan(value); if (!UseRadians) { angle = MathHelper.ToDegrees(angle); } value = angle; } break; default: throw new NotImplementedException($"Function {Function} has not been implemented."); } signal.value = value.ToString("G", CultureInfo.InvariantCulture); item.SendSignal(signal, "signal_out"); }
public float Asin(float a) => MathF.Asin(a);
public IsometricBuilder(IFramebufferHolder framebuffer, int width, int height, int diamondHeight, int tilesPerRow) { Framebuffer = framebuffer ?? throw new ArgumentNullException(nameof(framebuffer)); _labId = Base.Labyrinth.Test1; _layout = AttachChild(new IsometricLayout()); _width = width; _height = height; _pitch = ApiUtil.RadToDeg(MathF.Asin((float)diamondHeight / _width)); _tilesPerRow = tilesPerRow; On <IsoYawEvent>(e => { _yaw += e.Delta; Update(); }); On <IsoPitchEvent>(e => { _pitch += e.Delta; Update(); }); On <IsoRowWidthEvent>(e => { _tilesPerRow += e.Delta; if (_tilesPerRow < 1) { _tilesPerRow = 1; } Update(); }); On <IsoWidthEvent>(e => { _width += e.Delta; if (_width < 1) { _width = 1; } Update(); }); On <IsoHeightEvent>(e => { _height += e.Delta; if (_height < 1) { _height = 1; } Update(); }); On <IsoPaletteEvent>(e => { if (_paletteId == null) { _paletteId = e.Delta; } else { _paletteId += e.Delta; } if (_paletteId <= 0) { _paletteId = null; } Info($"PalId: {_paletteId}"); RecreateLayout(); }); On <IsoLabDeltaEvent>(e => { var newId = _labId.Id + e.Delta; if (newId < 0) { return; } _labId = new LabyrinthId(AssetType.Labyrinth, newId); Info($"LabId: {_labId} ({_labId.Id})"); RecreateLayout(); }); On <IsoLabEvent>(e => { _labId = e.Id; RecreateLayout(); }); On <IsoModeEvent>(e => { _mode = e.Mode; RecreateLayout(); }); }
public static float asin(float x) => MathF.Asin(x);
public static float Asin(float value) => MathF.Asin(value);
/// <summary> /// Converts a quaternion to euler angles /// </summary> public static Vector3 ToEuler(float w, float x, float y, float z, bool RotateZYX) { // normalize the values Quaternion vN = Quaternion.Normalize(new(x, y, z, w)); x = vN.X; y = vN.Y; z = vN.Z; w = vN.W; // this will have a magnitude of 0.5 or greater if and only if this is a singularity case Vector3 v = new(); if (RotateZYX) { float test = (w * x) - (y * z); // -M32 / 2 if (test > 0.4995f) // singularity at north pole { v.Z = 2f * MathF.Atan2(z, x); v.X = Pi * 0.5f; } else if (test < -0.4995f) // singularity at south pole { v.Z = -2f * MathF.Atan2(z, x); v.X = -Pi * 0.5f; } else { v.X = MathF.Asin(2f * test); // asin(-M32) v.Y = MathF.Atan2(2f * ((w * y) + (z * x)), 1 - (2f * ((y * y) + (x * x)))); // atan2(M31, M33) v.Z = MathF.Atan2(2f * ((w * z) + (y * x)), 1 - (2f * ((z * z) + (x * x)))); // atan2(M12,M22) } // here, z is only sometimes correct... weird. But the part above works, so idc this is only reference either way // x = MathF.Atan(-mtx.M32 / MathF.Sqrt(1 - (mtx.M32 * mtx.M32))); // y = MathF.Atan(mtx.M31 / mtx.M33); // z = MathF.Atan(mtx.M12 / mtx.M22); } else { float test = (w * y) - (x * z); // -M13 / 2 if (test > 0.4995f) // singularity at north pole { v.X = 2f * MathF.Atan2(x, y); v.Y = Pi * 0.5f; } else if (test < -0.4995f) // singularity at south pole { v.X = -2f * MathF.Atan2(x, y); v.Y = -Pi * 0.5f; } else { v.X = MathF.Atan2(2f * ((w * x) + (z * y)), 1 - (2f * ((y * y) + (x * x)))); //atan2(M23,M33) v.Y = MathF.Asin(2f * test); // asin(-M13) v.Z = MathF.Atan2(2f * ((w * z) + (y * x)), 1 - (2f * ((z * z) + (y * y)))); //atan2(M12,M11) } // x = MathF.Atan(mtx.M23 / mtx.M33); // y = MathF.Atan(-mtx.M13 / MathF.Sqrt(1 - (mtx.M13 * mtx.M13))); // z = MathF.Atan(mtx.M12 / mtx.M11); } v *= Rad2Deg;
public static float Asin(float x) { var result = MathF.Asin(x); return(float.IsNaN(result) ? 0f : result); }
public void updateDirectionVectors() { Yaw = MathF.Atan2(FrontDirection.X, FrontDirection.Z); Pitch = -MathF.Asin(FrontDirection.Y); }
public Test(Mode modeParam, TextWriter errorOutParam, TextWriter infoOutParam, Table table) { _table = table; _mode = modeParam; _errorOut = errorOutParam; _infoOut = infoOutParam; _failedOperations = new HashSet <string>(); // Validate parsing, this whole program expects little endian { uint val = 1234567891; if (Convert.ToUInt32(ToBinary(Convert.ToUInt32(ToBinary(val), 2)), 2) != val) { ReportError($"{nameof(ToBinary)} and back failed"); } } for (int testIndex = 0; testIndex < _table.Data.Length; testIndex++) { for (int testResult = 0; testResult < (_table.Data[testIndex].results?.Length ?? 0); testResult++) { var result = _table.Data[testIndex].results[testResult]; var asFloat = To <uint, float>(result.i); if (asFloat != result.f && !NaNAndBitsMatch(asFloat, result.f)) { ReportError($"FAILED PARSING {ToBinary(result.i)} to value {result.f.ToString("G9", CultureInfo.InvariantCulture)}, expected {ToBinary(result.f)}"); } } } for (int testIndex = 0; testIndex < _table.Data.Length; testIndex++) { float value = To <uint, float>(_table.Data[testIndex].initialValue); // Certain operations are funneling tests into specific ranges of values // so we aren't just using them as is, that is dVal's purpose in this code StartValidation(value); Validate(testIndex, "BIN", value); Validate(testIndex, "+", value + 0.1735f); Validate(testIndex, "-", value - 17f); Validate(testIndex, "*", value * 7.7757f); Validate(testIndex, "/", value / 0.3353f); Validate(testIndex, "%", value % 7.0f); // MATHF Validate(testIndex, nameof(MathF.Abs), MathF.Abs(value)); Validate(testIndex, nameof(MathF.Acos), MathF.Acos(value % 1f)); Validate(testIndex, nameof(MathF.Acosh), MathF.Acosh(1f + MathF.Abs(value))); Validate(testIndex, nameof(MathF.Asin), MathF.Asin(value % 1f)); Validate(testIndex, nameof(MathF.Asinh), MathF.Asinh(value)); Validate(testIndex, nameof(MathF.Atan), MathF.Atan(value)); Validate(testIndex, nameof(MathF.Atan2), MathF.Atan2(value, 0.17f)); Validate(testIndex, nameof(MathF.Atanh), MathF.Atanh(value % 1f)); Validate(testIndex, nameof(MathF.Cbrt), MathF.Cbrt(value)); Validate(testIndex, nameof(MathF.Ceiling), MathF.Ceiling(value)); Validate(testIndex, nameof(MathF.Cos), MathF.Cos(value)); Validate(testIndex, nameof(MathF.Cosh), MathF.Cosh(value % 2f)); Validate(testIndex, nameof(MathF.Exp), MathF.Exp(1f / value)); Validate(testIndex, nameof(MathF.Floor), MathF.Floor(value)); Validate(testIndex, nameof(MathF.FusedMultiplyAdd), MathF.FusedMultiplyAdd(value, 1.33f, -1.5f)); Validate(testIndex, nameof(MathF.IEEERemainder), MathF.IEEERemainder(value, 25.78f)); Validate(testIndex, nameof(MathF.Log), MathF.Log(MathF.Abs(value))); Validate(testIndex, nameof(MathF.Log) + "(x,y)", MathF.Log(MathF.Abs(value), 4f)); Validate(testIndex, nameof(MathF.Log2), MathF.Log2(MathF.Abs(value))); Validate(testIndex, nameof(MathF.Log10), MathF.Log10(MathF.Abs(value))); Validate(testIndex, nameof(MathF.Pow), MathF.Pow(MathF.Abs(value) % 1E+23f, 1.7f)); Validate(testIndex, nameof(MathF.ScaleB), MathF.ScaleB(value % 1E+23f, 2)); Validate(testIndex, nameof(MathF.Sin), MathF.Sin(value)); Validate(testIndex, nameof(MathF.Sinh), MathF.Sinh(value % 2f)); Validate(testIndex, nameof(MathF.Sqrt), MathF.Sqrt(MathF.Abs(value))); Validate(testIndex, nameof(MathF.Tan), MathF.Tan(value)); Validate(testIndex, nameof(MathF.Tanh), MathF.Tanh(value)); Validate(testIndex, nameof(MathF.Max), MathF.Max(value, 0.9f)); Validate(testIndex, nameof(MathF.MaxMagnitude), MathF.MaxMagnitude(value, -0.7f)); Validate(testIndex, nameof(MathF.Min), MathF.Min(value, 307f)); Validate(testIndex, nameof(MathF.MinMagnitude), MathF.MinMagnitude(value, -8.89f)); Validate(testIndex, nameof(MathF.Round), MathF.Round(value)); if (float.IsNaN(value) == false) { Validate(testIndex, nameof(MathF.Sign), MathF.Sign(value)); } Validate(testIndex, nameof(MathF.Truncate), MathF.Truncate(value)); // MATH double valueAsDouble = value; Validate(testIndex, $"D.{nameof(Math.Abs)}", Math.Abs(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Acos)}", Math.Acos(valueAsDouble % 1d)); Validate(testIndex, $"D.{nameof(Math.Acosh)}", Math.Acosh(1d + Math.Abs(valueAsDouble))); Validate(testIndex, $"D.{nameof(Math.Asin)}", Math.Asin(valueAsDouble % 1d)); Validate(testIndex, $"D.{nameof(Math.Asinh)}", Math.Asinh(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Atan)}", Math.Atan(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Atan2)}", Math.Atan2(valueAsDouble, 0.17d)); Validate(testIndex, $"D.{nameof(Math.Atanh)}", Math.Atanh(valueAsDouble % 1d)); Validate(testIndex, $"D.{nameof(Math.Cbrt)}", Math.Cbrt(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Ceiling)}", Math.Ceiling(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Cos)}", Math.Cos(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Cosh)}", Math.Cosh(valueAsDouble % 2d)); Validate(testIndex, $"D.{nameof(Math.Exp)}", Math.Exp(1d / valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Floor)}", Math.Floor(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.FusedMultiplyAdd)}", Math.FusedMultiplyAdd(valueAsDouble, 1.33d, -1.5d)); Validate(testIndex, $"D.{nameof(Math.IEEERemainder)}", Math.IEEERemainder(valueAsDouble, 25.78d)); Validate(testIndex, $"D.{nameof(Math.Log)}", Math.Log(Math.Abs(valueAsDouble))); Validate(testIndex, $"D.{nameof(Math.Log)}" + "(x,y)", Math.Log(Math.Abs(valueAsDouble), 4d)); Validate(testIndex, $"D.{nameof(Math.Log2)}", Math.Log2(Math.Abs(valueAsDouble))); Validate(testIndex, $"D.{nameof(Math.Log10)}", Math.Log10(Math.Abs(valueAsDouble))); Validate(testIndex, $"D.{nameof(Math.Pow)}", Math.Pow(Math.Abs(valueAsDouble) % 1E+23d, 1.7d)); Validate(testIndex, $"D.{nameof(Math.ScaleB)}", Math.ScaleB(valueAsDouble % 1E+23d, 2)); Validate(testIndex, $"D.{nameof(Math.Sin)}", Math.Sin(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Sinh)}", Math.Sinh(valueAsDouble % 2d)); Validate(testIndex, $"D.{nameof(Math.Sqrt)}", Math.Sqrt(Math.Abs(valueAsDouble))); Validate(testIndex, $"D.{nameof(Math.Tan)}", Math.Tan(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Tanh)}", Math.Tanh(valueAsDouble)); Validate(testIndex, $"D.{nameof(Math.Max)}", Math.Max(valueAsDouble, 0.9d)); Validate(testIndex, $"D.{nameof(Math.MaxMagnitude)}", Math.MaxMagnitude(valueAsDouble, -0.7d)); Validate(testIndex, $"D.{nameof(Math.Min)}", Math.Min(valueAsDouble, 307d)); Validate(testIndex, $"D.{nameof(Math.MinMagnitude)}", Math.MinMagnitude(valueAsDouble, -8.89d)); Validate(testIndex, $"D.{nameof(Math.Round)}", Math.Round(valueAsDouble)); if (float.IsNaN(value) == false) { Validate(testIndex, $"D.{nameof(Math.Sign)}", Math.Sign(valueAsDouble)); } Validate(testIndex, $"D.{nameof(Math.Truncate)}", Math.Truncate(valueAsDouble)); } }
public static float Asin(float x) { return(MathF.Asin(x)); }
public float Yaw() { return(MathF.Asin(MathV.Clamp(-2.0f * (x * z - w * y), -1.0f, 1.0f))); }
public static Vector2 ToYawPitch(this Vector3 vec) { return(new Vector2(MathF.Atan2(vec.X, vec.Z), MathF.Asin(vec.Y))); }
public static float XAudio2RadiansToCutoffFrequency(float Radians, float SampleRate) { return(SampleRate * MathF.Asin(Radians / 2.0f) / (float)3.14159265358979323846); }
public MathGenerator() { SupportedMethods = new[] { ReflectHelper.GetMethodDefinition(() => Math.Sin(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Cos(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Tan(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Sinh(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Cosh(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Tanh(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Asin(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Acos(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Atan(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Atan2(default(double), default(double))), ReflectHelper.GetMethodDefinition(() => Math.Sqrt(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(decimal))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(float))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(long))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(int))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(short))), ReflectHelper.GetMethodDefinition(() => Math.Abs(default(sbyte))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(decimal))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(double))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(float))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(long))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(int))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(short))), ReflectHelper.GetMethodDefinition(() => Math.Sign(default(sbyte))), ReflectHelper.GetMethodDefinition(() => Math.Floor(default(decimal))), ReflectHelper.GetMethodDefinition(() => Math.Floor(default(double))), ReflectHelper.GetMethodDefinition(() => decimal.Floor(default(decimal))), ReflectHelper.GetMethodDefinition(() => Math.Ceiling(default(decimal))), ReflectHelper.GetMethodDefinition(() => Math.Ceiling(default(double))), ReflectHelper.GetMethodDefinition(() => decimal.Ceiling(default(decimal))), ReflectHelper.GetMethodDefinition(() => Math.Pow(default(double), default(double))), #if NETCOREAPP2_0 ReflectHelper.GetMethodDefinition(() => MathF.Sin(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Cos(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Tan(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Sinh(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Cosh(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Tanh(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Asin(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Acos(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Atan(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Atan2(default(float), default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Sqrt(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Abs(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Sign(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Floor(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Ceiling(default(float))), ReflectHelper.GetMethodDefinition(() => MathF.Pow(default(float), default(float))), #endif }; }
private float HandleMathsExpresison(string expression) { float value = 0; ///////////////////////////////////////////////////////// //Sort out brackets here and do them first recursively foreach (Match c in bracketRegex.Matches(expression)) { //This goes and recursively solves brackets expression = expression.Replace(c.Value, HandleMathsExpresison(c.Value.Substring(1, c.Value.Length - 2)).ToString()); } if (squareBracketRegex.Match(expression).Success) //If an array reference is found, replace it with the correct array index value { string brackets = squareBracketRegex.Match(expression).Value; int index = (int)HandleMathsExpresison(brackets.Substring(1, brackets.Length - 2)); expression = expression.Replace(brackets, arrayDelimiter + index.ToString()); } ///////////////////////////////////////////// //Break down into tokens based on basic operators string[] parts = Regex.Split(expression, @"(\+|\*|\-|/|\^)"); for (int i = 0; i < parts.Length; i++) { if (variables.ContainsKey(parts[i])) //If a variable is found, replace it with the variables value { parts[i] = variables[parts[i]].ToString(); } else if (squareBracketRegex.Match(parts[i]).Success) //If an array reference is found, replace it with the correct array index value { string brackets = squareBracketRegex.Match(parts[i]).Value; string arrayName = parts[i].Replace(brackets, ""); int index = (int)HandleMathsExpresison(brackets.Substring(1, brackets.Length - 2)); parts[i] = GetArrayItem(arrayName, index).ToString(); } } ////////////////////////////////////////////////////////////////////////// //Check for functions and solve them here for (int i = 0; i < parts.Length; i++) { if (parts[i].StartsWith("Sin")) { parts[i] = MathF.Sin(float.Parse(parts[i].Substring(3))).ToString(); } else if (parts[i].StartsWith("Asin")) { parts[i] = MathF.Asin(float.Parse(parts[i].Substring(4))).ToString(); } else if (parts[i].StartsWith("Sign")) { parts[i] = MathF.Sign(float.Parse(parts[i].Substring(4))).ToString(); } else if (parts[i].StartsWith("Sqrt")) { parts[i] = MathF.Sqrt(float.Parse(parts[i].Substring(4))).ToString(); } else if (parts[i].StartsWith("Log")) { parts[i] = MathF.Log(float.Parse(parts[i].Substring(3))).ToString(); } } //////////////////////////////////////////////////////////////////////// //Go on to do mathmatical calculationss value = EvaluateMathsEquation(parts); return(value); }
public static float Asin(float v) => MathF.Asin(v);