private static void TestFactorialValue(int initial, int expected, string message="") { MathOperations implementation = new MathOperations(); int actual = implementation.Factorial(initial); Assert.AreEqual(expected, actual, message); }
public void ShouldMultiply2Integers() { //Arrange var x = 2; var y = 3; var expected = "x * y = 6"; IMathOperations mathOperations = new MathOperations(x, y); //Act var result = mathOperations.Multiply(); //Assert Assert.AreEqual(expected, result); }
public void ShouldAdd2Integers() { //Arrange var x = 2; var y = 3; var expected = "x + y = 5"; IMathOperations mathOperations = new MathOperations(x, y); //Act var result = mathOperations.Add(); //Assert Assert.AreEqual(expected, result); }
public void Operators(int option, ref int val1,ref int val2 ) { MathOperations mt = new MathOperations(); switch(option) { case 1: { Console.WriteLine("The {0} is ... {1}",Operations.Addition, mt.Addition(ref val1, ref val2)); } break; case 2: { Console.WriteLine("The {0} is ... {1}",Operations.Subtraction, mt.Subtraction(ref val1, ref val2)); } break; case 3: { Console.WriteLine("The {0} is ... {1}",Operations.Multiplication, mt.Multiplication(ref val1, ref val2)); } break; case 4: { Console.WriteLine("The {0} is ... {1}",Operations.Division, mt.Division(ref val1, ref val2)); } break; case 5: { Console.WriteLine("the {0} is ...{1}", Operations.Exponentation, mt.Exponentation(ref val1, ref val2)); } break; case 6: { Console.Clear(); Console.WriteLine("....."); Matrix mx = new Matrix(); mx.MainMatrix(); } break; case 7: { LinearEquation le = new LinearEquation(); le.EquationSolver(); } break; default: Console.WriteLine("Wrong Choice"); break; } }
private void FrmAddTel_Load(object sender, EventArgs e) { telNoTableAdapter.Fill(auditorDataSet.TelNo); locationTableAdapter.Fill(auditorDataSet.Location); ComboLocation.SelectedIndex = -1; ComboTelNo.SelectedIndex = -1; TxtAmount.Clear(); TxtStamp.Clear(); TxtSellTax.Clear(); TxtPercentage.Text = @"2"; ComboStatus.SelectedIndex = 0; MathOperations.NetAmount(TxtAmount, TxtSellTax, TxtStamp, TxtTotalDiscount, TxtNetAmount, TxtPercentage, TxtTax, TxtPaidAmount); BtnSave.Enabled = false; }
private void TxtAmount_TextChanged(object sender, EventArgs e) { // Calculate Discounts by rates: MathOperations.PrePay(TxtAmount, TxtTaxRate, TxtTaxAmount, TxtSellTax, TxtBillTotal, CheckFees, TxtFees, TxtTotalDiscount, TxtNetAmount); //Formatting Form: if (ComboLocation.Text == "" || ComboVendor.Text == "" || ComboBridge.Text == "" || TxtDocNo.Text == "" || TxtAmount.Text == "0" || TxtReason.Text == "") { BtnAdd.Enabled = false; } else { BtnAdd.Enabled = true; } }
private static (int qScore, float[] phredPosteriors) CalculateQScoreAndGenotypePosteriors(int alleleDepth, int totalDepth, int category, double[] means, double[] priors, int[] maxN) { float[] phredScores = new float[means.Length]; double[] posteriors = CalculatePosteriorsWithMaxN(alleleDepth, totalDepth, means, priors, maxN); for (int i = 0; i < means.Length; i++) { phredScores[i] = Math.Min(_maxQScore, MathOperations.PToQ_CapAt300(posteriors[i])); } var qScore = Math.Min((int)_maxQScore, (int)Math.Round(MathOperations.PToQ_CapAt300(1 - posteriors[category]))); return(qScore, phredScores); }
private void TxtDocNo_TextChanged(object sender, EventArgs e) { // Formatting the form: if (TxtDocNo.Text == "" || ComboLocation.Text == "" || ComboName.Text == "" || TxtDestination.Text == "" || TxtPeriod.Text == "" || TxtTrans.Text == @"0" & TxtTravel.Text == @"0") { BtnAdd.Enabled = false; } else { BtnAdd.Enabled = true; } MathOperations.AmountZeroFormat(TxtTrans); MathOperations.AmountZeroFormat(TxtTravel); }
private void Apply_Click(object sender, RoutedEventArgs e) { try { Name = Name_textbox.Text; Surname = Surname_textbox.Text; Sex = SexCheck; Age = Convert.ToUInt32(Age_textbox.Text); Height = Convert.ToDouble(Height_textbox.Text.Replace('.', ',')); Weight = Convert.ToDouble(Weight_textbox.Text.Replace('.', ',')); ActivityLevel = Convert.ToUInt32(ActivityLevel_combobox.SelectedIndex); Goal = Convert.ToUInt32(Goal_combobox.SelectedIndex); DietType = Convert.ToUInt32(DietCheck()); MealCount = Convert.ToUInt32(MealsCount_combobox.SelectedItem); BMI = MathOperations.getBMI(Height, Weight); BMR = MathOperations.getBMR(Height, Weight, Convert.ToInt32(Age), Sex); TMR = MathOperations.getTMR(Convert.ToInt32(ActivityLevel), BMR); DailyCalories = MathOperations.getDailyCalories(Convert.ToInt32(Goal), TMR); BMI_textblock.Text = BMI.ToString("0.##"); BMR_textblock.Text = BMR.ToString(); TMR_textblock.Text = TMR.ToString(); DailyCalories_textblock.Text = DailyCalories.ToString(); Meals meals = new Meals(Convert.ToInt32(MealCount), DailyCalories, Convert.ToInt32(DietType), Convert.ToInt32(Goal), Weight); uint sex; if (Sex) { sex = 1; } else { sex = 0; } Users user = new Users(Login.UserLogin, Name, Surname, Age, Height, Weight, Goal, sex, ActivityLevel, DailyCalories, DietType, MealCount); UsersRepos.Update(user); } catch { MessageBox.Show(Properties.Resources.errorEmptyDatas, Properties.Resources.warning); } show(); }
public void CalculateMSG(int maxiter, double eps) { double alpha; double beta; double discrepancy; var iterationCount = 0; //начальное решение for (var i = 0; i < N; i++) { q[i] = 0; } var r = MathOperations.MatrixMult(N, A, q); for (var i = 0; i < N; i++) { r[i] = b[i] - r[i]; } var z = new double[N]; r.CopyTo(z, 0); do { ++iterationCount; var Az = MathOperations.MatrixMult(N, A, z); alpha = MathOperations.ScalarMult(r, r) / MathOperations.ScalarMult(Az, z); var temp = MathOperations.ScalarMult(r, r); Parallel.For(0, N, i => { q[i] = q[i] + alpha * z[i]; r[i] = r[i] - alpha * Az[i]; }); beta = MathOperations.ScalarMult(r, r) / temp; Parallel.For(0, N, i => { z[i] = r[i] + beta * z[i]; }); discrepancy = MathOperations.ScalarMult(r, r); }while (iterationCount < maxiter && discrepancy > eps); using (var sw = new StreamWriter("msg_log.txt", true, System.Text.Encoding.Default)) { sw.WriteLine($"Погрешность: {discrepancy}\nЧисло итераций: {iterationCount}"); } }
private void TxtAmount_TextChanged(object sender, EventArgs e) { MathOperations.NetAmount(TxtAmount, TxtSellTax, TxtStamp, TxtTotalDiscount, TxtNetAmount, TxtPercentage, TxtTax, TxtPaidAmount); //Button Update Format: if (ComboDocNo.Text == "" || ComboLocation.Text == "" || TxtPortion.Text == "" || TxtAmount.Text == Resources.Zero || ComboStatus.Text == "") { BtnUpdate.Enabled = false; } else { BtnUpdate.Enabled = true; } }
IEnumerator SpawnBoss(float delay) { music.clip = bossMusic; music.Play(); GameObject go = Instantiate(bossWavePrefab); go.transform.SetParent(messagePad.transform); yield return(new WaitForSeconds(delay)); GameObject g = Instantiate(boss, GravityBody.GetSpawnPos(), MathOperations.LookAt2D(transform.position, chara.transform.position, 90)); chara.ConfigurePointers(); chara.hp = chara.maxHp; waveIndex++; started = false; }
/// <summary> /// Walks each character of a string, converting to a integer, and adding it's representation together /// finally returning a long. /// Example: /// "123" /// becomes /// 100 + 20 + 3 /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="long"/>. /// </returns> /// <exception cref="ArgumentException"> /// When the value contains characters that aren't digits (or a starting minus sign). /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// When the value is larger or smaller than what can be contained by a long value type. /// </exception> private static long IndividualIntegers(string value) { if (!RegexDigits.IsMatch(value)) { throw new ArgumentException("Value must contain only digits (minus sign optional)"); } bool isNegative = value[0] == '-'; MathOperations operation = isNegative ? MathOperations.Subtraction : MathOperations.Addition; int startPosition = isNegative ? 1 : 0; long newLong = 0; for (int i = startPosition; i < value.Length; i++) { // http://www.alanwood.net/demos/ansi.html // char ansi/unicode number // 0 48 // 1 49 // ... // 9 57 // therefore // example: // "9" = 57 - 48 = 9 // "0" = 48 - 48 = 0 var digit = (int)value[i] - 48; try { checked { var exponent = (value.Length - 1) - i; long operand = digit * (long)Math.Pow(10, exponent); newLong = PerformOperation(newLong, operand, operation); } } catch (OverflowException) { throw new ArgumentOutOfRangeException( "value", value, "Value is larger or smaller than what can be stored as a long."); } } return(newLong); }
public override float[] ReadState() { float[] qr = new float[6]; qr[0] = -link1.transform.localRotation.eulerAngles.z * Mathf.PI / 180; qr[1] = -(link2.transform.localRotation.eulerAngles.y - 90) * Mathf.PI / 180; qr[2] = -(link3.transform.localRotation.eulerAngles.y + 90) * Mathf.PI / 180; qr[3] = link4.transform.localRotation.eulerAngles.x * Mathf.PI / 180; qr[4] = -link5.transform.localRotation.eulerAngles.y * Mathf.PI / 180; qr[5] = link6.transform.localRotation.eulerAngles.x * Mathf.PI / 180; for (int i = 0; i < 6; i++) { qr[i] = MathOperations.AngleRound(qr[i]); } return(qr); }
private void TxtSettlementPeriod_TextChanged(object sender, EventArgs e) { // Formatting the form: MathOperations.PeriodZeroFormat(TxtSettlementPeriod); try { int.Parse(TxtSettlementPeriod.Text); } catch (Exception EX) { MessageBox.Show(EX.Message); } // Math operations: MathOperations.TemporaryLoan(TxtTotalAmount, TxtSettlementAmount, TxtTax, TxtPenalty, TxtFees, TxtRevenues, TxtTotalDiscount, TxtNetAmount, TxtAmountToPay, TxtPaidAmount); MathOperations.TempLoanPenalty(TxtPeriod, TxtSettlementPeriod, TxtTotalAmount, TxtPenalty); }
void Rotate() { Vector2 rotationVector = transform.position; if (Camera.main != null) { rotationVector = Camera.main.ScreenToWorldPoint(Input.mousePosition); } else { Debug.LogError("Add a Camera with the tag MainCamera to the scene!"); } Quaternion desiredRot = MathOperations.LookAt2D(rotationVector, transform.position, -90); transform.rotation = Quaternion.Slerp(transform.rotation, desiredRot, turningSpeed * Time.deltaTime); }
//Removes duplicate vectors based symmetry public static List <Point> RemoveDuplicateVectors(List <Point> allVectors) { Dictionary <string, int> uniqueVectorDictionary = new Dictionary <string, int>(); foreach (Point thisVector in allVectors) { var sortedVector = thisVector.ToLexicographicalString(); //check 1: unique when sorted in lexicographical order if (!uniqueVectorDictionary.ContainsKey(sortedVector)) { int gcd = Convert.ToInt32(sortedVector.Substring(sortedVector.Length - 1)); //check 2: gcd of all coords = 1 for (int i = 0; i < Globals.d - 1; i++) { if (Convert.ToInt32(sortedVector.Substring(i, 1)) == 0) { continue; } gcd = MathOperations.GCD(Convert.ToInt32(sortedVector.Substring(i, 1)), gcd); if (gcd == 1) { break; } } if (gcd == 1) { uniqueVectorDictionary.Add(sortedVector, 0); } } } var uniqueVectors = new List <Point>(); foreach (string key in uniqueVectorDictionary.Keys) { uniqueVectors.Add(new Point(key)); } return(uniqueVectors); }
private void Update() { GetComponent <Rigidbody2D>().velocity = Vector2.zero; if (target != null) { if (Vector2.Distance(transform.position, target.position) > stoppingDistance) { transform.position += transform.up * 4 * Time.deltaTime; } if (Physics2D.Linecast(transform.position, target.position, obstacles)) { if (savedVector == Vector2.zero || Physics2D.Raycast(transform.position, transform.up, stoppingDistance, obstacles)) { int index = Random.Range(0, 2); switch (index) { case 0: savedVector = transform.right; break; case 1: savedVector = -transform.right; break; } } transform.rotation = Quaternion.Slerp(transform.rotation, MathOperations.LookAt2D((Vector2)transform.position + savedVector, transform.position, -90), rotationSpeed * Time.deltaTime); } else { savedVector = Vector2.zero; //rotate the enemy (or just the enemy weapon) towards the player transform.rotation = Quaternion.Slerp(transform.rotation, MathOperations.LookAt2D(target.position, transform.position, -90), rotationSpeed * Time.deltaTime); //call the ai shoot function on aiWeapon!! //remember to configure a Weapon2DPreset for the enemy!!! if (!no) { aiWeapon.AIShoot(); } } } else { PatrolRotate(); transform.position += transform.up * 1 * Time.deltaTime; } }
public override void Move() { base.Move(); if (target == null) { StartCoroutine(FindTarget()); } else { StopCoroutine(FindTarget()); transform.rotation = Quaternion.Slerp(transform.rotation, MathOperations.LookAt2D(target.position, transform.position, -90), homingAccuracy * Time.deltaTime); } destroyTimer -= Time.deltaTime; if (destroyTimer <= 0) { Destruction(); } }
private static double Snap(double pointToSnap, IEnumerable <double> edges) { double snappedX = 0; var snapped = false; var enumerator = edges.GetEnumerator(); while (enumerator.MoveNext() && !snapped) { var horizontalEdge = enumerator.Current; snappedX = MathOperations.Snap(pointToSnap, horizontalEdge, 10); if (Math.Abs(snappedX - pointToSnap) > 0.1) { snapped = true; } } return(snappedX); }
void PatrolRotate() { transform.rotation = MathOperations.LookAt2D((Vector2)transform.position + ang.normalized, transform.position, -90); if (Physics2D.Raycast(transform.position, transform.up, stoppingDistance, obstacles)) { int index = Random.Range(0, 2); switch (index) { case 0: ang = transform.right; break; case 1: ang = -transform.right; break; } } }
private double Snap(double original, IEnumerable <Edge> edges) { var snappedValue = original; var alreadySnapped = false; var enumerator = edges.GetEnumerator(); while (enumerator.MoveNext() && !alreadySnapped) { var currentEdge = enumerator.Current; snappedValue = MathOperations.Snap(original, currentEdge.AxisDistance, Threshold); alreadySnapped = ValueIsSnapped(original, snappedValue); } return(snappedValue); }
Dictionary <MutationCategory, int> GetPhredScaledCalibratedRatesForEdges(int baselineQNoise, double warningThreshold, CountData basicCountsData, CountData edgeIssueCountsData) { Dictionary <MutationCategory, int> AdjustedErrorRates = new Dictionary <MutationCategory, int>(); double GeneralEdgeRiskIncrease = edgeIssueCountsData.ObservedMutationRate / basicCountsData.ObservedMutationRate; if (GeneralEdgeRiskIncrease > warningThreshold) { Logger.WriteToLog("Warning, high levels of mismatches detected at loci near edges, relative to all other loci, by a factor of " + GeneralEdgeRiskIncrease); } double MutationRateInEdge = edgeIssueCountsData.ObservedMutationRate; double MuationsCalledNotInEdge = basicCountsData.TotalMutations - edgeIssueCountsData.TotalMutations; double TotalLociNotInEdge = basicCountsData.NumPossibleVariants - edgeIssueCountsData.NumPossibleVariants; double MutationRateNotInEdge = MuationsCalledNotInEdge / TotalLociNotInEdge; //if the error rate at the edges was the same as the error rate in the middle, // we would expect this many variants at the edges: double NullHypothesisExpectedMismatches = MutationRateNotInEdge * edgeIssueCountsData.NumPossibleVariants; double HowManyVariantsWeActuallySaw = edgeIssueCountsData.TotalMutations; double HowManyAreProbablyWrong = edgeIssueCountsData.TotalMutations - NullHypothesisExpectedMismatches; //error rate in edge region, Given You Called a Variant. double EstimatedErrorRateInEdgeRegions = HowManyAreProbablyWrong / edgeIssueCountsData.TotalMutations; foreach (var cat in edgeIssueCountsData.CountsByCategory.Keys) { double countsAtEdge = edgeIssueCountsData.CountsByCategory[cat]; double overallMutations = edgeIssueCountsData.TotalMutations; double proportion = countsAtEdge / edgeIssueCountsData.TotalMutations; //how much this particular variant category contributed to the error rate increase double estimatedErrorRateByCategory = proportion * EstimatedErrorRateInEdgeRegions; int riskAsQRate = (int)MathOperations.PtoQ(estimatedErrorRateByCategory); AdjustedErrorRates.Add(cat, riskAsQRate); } return(AdjustedErrorRates); }
public static int Compute(CalledAllele allele, float targetLimitOfDetectionVF, int minGTQScore, int maxGTQScore) { double rawQ = allele.VariantQscore; if ((allele.TotalCoverage == 0) || (allele.IsNocall)) { return(minGTQScore); } if ((allele.Genotype == Genotype.HomozygousRef) || (allele.Genotype == Genotype.HomozygousAlt)) { //a homozygous somatic call GT is a fairly strong statement. It implies //A) we found the allele for sure (the VariantQscore) var p1 = MathOperations.QtoP(allele.VariantQscore); //and //B) the chance that we missed any alternate calls is very small. // this would be the chance false negative given VF=min freq, and coverage is as given. //these are explictly typed, to prevent any win/linux diffs sneaking in // in float -> double conversions inside downstream arguments float nonAlleleObservationsF = (1f - allele.Frequency) * allele.TotalCoverage; float expectedNonAllelObservationsF = targetLimitOfDetectionVF * allele.TotalCoverage; //This takes care of the cases: //A) we dont have enough depth to ever observe any non-ref variant. If, if depth is 10, we would never see a 5% variant anyway. //B) if we see 6% not reference > 5% min safe var call freqeuncy, we are pretty worried about calling this as a 0/0 GT if (nonAlleleObservationsF >= expectedNonAllelObservationsF) { return(minGTQScore); } //var p2 = poissonDist.CumulativeDistribution(nonRefObservations); <- this method does badly for values lower than the mean var p2 = Poisson.Cdf(nonAlleleObservationsF, expectedNonAllelObservationsF); rawQ = MathOperations.PtoQ(p1 + p2); } var qScore = Math.Min(maxGTQScore, rawQ); qScore = Math.Max(qScore, minGTQScore); return((int)Math.Round(qScore)); }
private static void MathOperationsExample() { // I don't think that for checking are numbers prime we should throw an exception var numbers = new List <int>(); foreach (var number in numbers) { var isPrime = MathOperations.IsPrime(number); if (isPrime) { Console.WriteLine("{0} is prime!", number); } else { Console.WriteLine("{0} is NOT prime!", number); } } }
private void ComboReservedRefund_TextChanged(object sender, EventArgs e) { //Formatting Form: if (TxtPredicationOrder.Text == "" || ComboLocation.Text == "" || ComboContractor.Text == "" || TxtExcuteOrder.Text == "" || TxtPeriod.Text == "0" || ComboDocNo.Text == "" || TxtOperation.Text == "" || TxtAmount.Text == "0" || ComboReservedRefund.Text == "" || ComboInsuranceRefund.Text == "" || TxtJustAmount.Text == "") { BtnUpdate.Enabled = false; } else { BtnUpdate.Enabled = true; } // if (ComboReservedRefund.Text == "تم الرد") { LblResStatues.Enabled = true; LblResDocNo.Enabled = true; LblResPayDate.Enabled = true; LblResDiscount.Enabled = true; LblResPaid.Enabled = true; TxtReservedDocNo.Enabled = true; DateResevedPay.Enabled = true; TxtResDiscountPercentage.Enabled = true; } else { TxtReservedDocNo.Text = null; TxtResDiscountPercentage.Text = "0.0"; LblResStatues.Enabled = false; LblResDocNo.Enabled = false; LblResPayDate.Enabled = false; LblResDiscount.Enabled = false; LblResPaid.Enabled = false; TxtReservedDocNo.Enabled = false; DateResevedPay.Enabled = false; TxtResDiscountPercentage.Enabled = false; } // MathOperations.AfterPayProject(ComboReservedRefund, TxtAmount, TxtReservedAmount, TxtResDiscountPercentage, TxtResDiscountAmount, TxtReservedPaid); }
private float[] CalcErorr(Matrix <float> goal, Matrix <float> end_effector) { float[] err = new float[6]; err[0] = goal[0, 3] - end_effector[0, 3]; err[1] = goal[1, 3] - end_effector[1, 3]; err[2] = goal[2, 3] - end_effector[2, 3]; float[] t1 = new float[] { Mathf.Atan2(goal[2, 1], Mathf.Sqrt(1 - goal[2, 1] * goal[2, 1])), Mathf.Atan2(-goal[0, 1], goal[1, 1]), Mathf.Atan2(-goal[2, 0], goal[2, 2]) }; float[] t2 = new float[] { Mathf.Atan2(end_effector[2, 1], Mathf.Sqrt(1 - end_effector[2, 1] * end_effector[2, 1])), Mathf.Atan2(-end_effector[0, 1], end_effector[1, 1]), Mathf.Atan2(-end_effector[2, 0], end_effector[2, 2]) }; Matrix <float> R = Matrix <float> .Build.DenseOfArray(new float[, ] { { 0, Mathf.Cos(t1[1]), -Mathf.Sin(t1[1]) * Mathf.Cos(t1[0]) }, { 0, Mathf.Sin(t1[1]), Mathf.Cos(t1[1]) * Mathf.Cos(t1[0]) }, { 1, 0, Mathf.Sin(t1[0]) } }); float d1 = t1[0] - t2[0]; float d2 = t1[1] - t2[1]; float d3 = t1[2] - t2[2]; err[3] = (R[0, 0] * d2 + R[0, 1] * d1 + R[0, 2] * d3); err[4] = (R[1, 0] * d2 + R[1, 1] * d1 + R[1, 2] * d3); err[5] = (R[2, 0] * d2 + R[2, 1] * d1 + R[2, 2] * d3); err[3] = MathOperations.AngleRound(err[3]); err[4] = MathOperations.AngleRound(err[4]); err[5] = MathOperations.AngleRound(err[5]); return(err); }
private Matrix <float> AGILUSjacobian(float[] q) { Matrix <float> A1 = MathOperations.CalcMatrixDH(q[0], 400, 25, Mathf.PI / 2); Matrix <float> A2 = MathOperations.CalcMatrixDH(q[1] + Mathf.PI / 2, 0, 560, 0); Matrix <float> A3 = MathOperations.CalcMatrixDH(q[2], 0, 35, Mathf.PI / 2); Matrix <float> A4 = MathOperations.CalcMatrixDH(q[3], 515, 0, -Mathf.PI / 2); Matrix <float> A5 = MathOperations.CalcMatrixDH(q[4], 0, 0, Mathf.PI / 2); Matrix <float> A6 = MathOperations.CalcMatrixDH(q[5], 80, 0, 0); Matrix <float> T1 = A1; Matrix <float> T2 = A1.Multiply(A2); Matrix <float> T3 = A1.Multiply(A2.Multiply(A3)); Matrix <float> T4 = A1.Multiply(A2.Multiply(A3.Multiply(A4))); Matrix <float> T5 = A1.Multiply(A2.Multiply(A3.Multiply(A4.Multiply(A5)))); Matrix <float> T6 = A1.Multiply(A2.Multiply(A3.Multiply(A4.Multiply(A5.Multiply(A6))))); Vector3 z0 = new Vector3(0, 0, 1); Vector3 z1 = new Vector3(T1[0, 2], T1[1, 2], T1[2, 2]); Vector3 z2 = new Vector3(T2[0, 2], T2[1, 2], T2[2, 2]); Vector3 z3 = new Vector3(T3[0, 2], T3[1, 2], T3[2, 2]); Vector3 z4 = new Vector3(T4[0, 2], T4[1, 2], T4[2, 2]); Vector3 z5 = new Vector3(T5[0, 2], T5[1, 2], T5[2, 2]); Vector3 z6 = new Vector3(T6[0, 2], T6[1, 2], T6[2, 2]); Vector3 p0 = new Vector3(0, 0, 0); Vector3 p1 = new Vector3(T1[0, 3], T1[1, 3], T1[2, 3]); Vector3 p2 = new Vector3(T2[0, 3], T2[1, 3], T2[2, 3]); Vector3 p3 = new Vector3(T3[0, 3], T3[1, 3], T3[2, 3]); Vector3 p4 = new Vector3(T4[0, 3], T4[1, 3], T4[2, 3]); Vector3 p5 = new Vector3(T5[0, 3], T5[1, 3], T5[2, 3]); Vector3 p6 = new Vector3(T6[0, 3], T6[1, 3], T6[2, 3]); Matrix <float> J = Matrix <float> .Build.DenseOfArray(new float[, ] { { Vector3.Cross(z0, p6 - p0).x, Vector3.Cross(z1, p6 - p1).x, Vector3.Cross(z2, p6 - p2).x, Vector3.Cross(z3, p6 - p3).x, Vector3.Cross(z4, p6 - p4).x, Vector3.Cross(z5, p6 - p5).x }, { Vector3.Cross(z0, p6 - p0).y, Vector3.Cross(z1, p6 - p1).y, Vector3.Cross(z2, p6 - p2).y, Vector3.Cross(z3, p6 - p3).y, Vector3.Cross(z4, p6 - p4).y, Vector3.Cross(z5, p6 - p5).y }, { Vector3.Cross(z0, p6 - p0).z, Vector3.Cross(z1, p6 - p1).z, Vector3.Cross(z2, p6 - p2).z, Vector3.Cross(z3, p6 - p3).z, Vector3.Cross(z4, p6 - p4).z, Vector3.Cross(z5, p6 - p5).z }, { z0.x, z1.x, z2.x, z3.x, z4.x, z5.x }, { z0.y, z1.y, z2.y, z3.y, z4.y, z5.y }, { z0.z, z1.z, z2.z, z3.z, z4.z, z5.z } }); return(J); }
private ElementBase InitializeElementBaseByMinMaxPoint() { const int nils = 3; var multiplier = (int)Math.Pow(10, nils); var X = (int)Math.Round((MaxMinPoint[1].X - MaxMinPoint[0].X) * multiplier, 0); var Y = (int)Math.Round((MaxMinPoint[1].Y - MaxMinPoint[0].Y) * multiplier, 0); var Z = (int)Math.Round((MaxMinPoint[1].Z - MaxMinPoint[0].Z) * multiplier, 0); var xLength = X.ToString().Length; var yLength = Y.ToString().Length; var zLength = Z.ToString().Length; var minLength = (int)MathOperations.FindMin(xLength, yLength, zLength); var size = minLength >= 6 ? elementSize : 0.1; //int size = (int)Math.Pow(10, minLength - (nils + 1)); // 2 is a kind of magic... return new ElementBase(size); }
public void EvaluateTurningLeft() { Vector3 v1 = new Vector3(hips.transform.forward.z, 0, hips.transform.forward.x); Vector3 v2 = new Vector3(animationManager.InputX.Value, 0, animationManager.InputY.Value); MathOperations.RotateVector(ref v2, animationManager.CamRotation.angle); GetComponent <TurningLeft>().LastInputOnPreviousAnimation = new Vector2(lastX, lastY); // Debug.Log("v1 : " + v1); // Debug.Log("v2 : " + v2); Vector3 cross = Vector3.Cross(v1.normalized, v2.normalized); if (cross.y > 0.85f) { animationManager.changeAnimation("leftTurn"); turningRight = true; } }
public static void Give_Two_Vectors_Check_Sum() { var vec1 = new Vector(1, 1, 1); var vec2 = new Vector(2, 2, 2); var vec3 = new Vector(3, 3, 3); var sum = MathOperations.Sum(vec1, vec2); for (int i = 0; i < 3; i++) { Assert.Equal(3, sum[i]); } var sum2 = MathOperations.Sum(sum, vec3); for (int i = 0; i < 3; i++) { Assert.Equal(6, sum2[i]); } }
Vector GetInputs() { Vector input = new Vector(0); int half = visions / 2; for (int i = 0; i < visions; i++) { float val = ((float)i - half + (visions % 2 == 0 ? 0.5f : 0f)) * (visionAngle * (1f / (float)visions)); Vector2 dir = MathOperations.AngleToVector(val + transform.rotation.eulerAngles.z + 90); Vector visionVector = GetVision(dir); input.JoinVector(visionVector); //Debug.DrawLine(transform.position, transform.position + (Vector3)dir * visionDst, Color.blue); } input.JoinVector(GetSound()); float[] arr = { vitality / maxVitality }; input.JoinVector(new Vector(arr)); input.JoinVector(op); return(input); }
static float Calc(float x, float y, MathOperations z) { float res = 0f; switch (z) { case MathOperations.add: res = x + y; break; case MathOperations.div: res = x - y; break; case MathOperations.mul: res = x * y; break; case MathOperations.sub: res = x / y; break; } return res; }
public ExpressionTree(MathOperations.MathOperation val) { Value = val; }
public void SetUp() { _math = new MathOperations(); _cvm = new CalcViewModel(); }