public static float GetLookAtAngle2D(this Transform transform, Vector3 target) { var diff = target - transform.position; float rotZ = AngleMath.VectorToAngle2D(diff); return(rotZ); }
/// <summary> /// Calculate prayer time for asr. /// </summary> private static double ComputeAsrTime(double jd, int juristicTimeOfShadow, double latitude) { var dayFraction = AstronomyMath.GetDayFraction(AsrDefaultTime); var sunDeclination = AstronomyMath.ComputeSunDeclination(jd + dayFraction); var angle = -AngleMath.InverseCotangentInDegree(juristicTimeOfShadow + AngleMath.TangentOfDegree(Math.Abs(latitude - sunDeclination))); var asrTime = AstronomyMath.ComputeSolarTime(jd, dayFraction, angle, latitude, Direction.Clockwise); return(asrTime); }
public void ProcessMessage(InputMessage message) { if (message.InputType != InputMessage.InputTypes.OneFingerDrag) { return; } if (message.MessageType == InputMessage.MessageTypes.Update || message.MessageType == InputMessage.MessageTypes.Begin) { _raycast.Invalidate(); Vector2 delta = message.FingerDeltas[0]; //Debug.Log(string.Format("mag: {0}, didHit: {1}", _input.Delta.magnitude, _raycast.DidHit)); if (delta.magnitude > _startThreshold && _raycast.DidHit) { float angle = AngleMath.AngleSigned(Vector3.forward, _targetCamera.transform.forward, Vector3.up); _worldDelta = Quaternion.AngleAxis(angle, Vector3.up) * FlexiUtils.SwapYZ(message.NormalisedFingerDeltas[0]) * (_panFactor * _raycast.Distance) * (_invert ? -1f : 1f); _worldDelta = Vector3.ClampMagnitude(_worldDelta, _deltaClamp); float distance = Vector3.Distance(_center, _raycast.HitPoint); if (_limited && distance > _limitStart) { float overshoot = (distance - _limitStart); float factor = 1f - Mathf.Clamp((overshoot / _limitEnd), 0f, 1f); float a = Vector3.Angle(_worldDelta.normalized, -_raycast.HitPoint.normalized); if (a > 90f) { _worldDelta *= factor; } } _deltaPos = _worldDelta; _pendingUpdate = true; message.Use(); } } else { if (_worldDelta.magnitude > _startThreshold) { Vector3 mod = _worldDelta; _worldDelta *= _dampingFactor; _deltaPos = mod; _pendingUpdate = true; return; } } }
/// <summary> /// Calculates the distance between all particle values and a given value. /// </summary> /// <param name="othervalue">The value to compare the particle values with.</param> /// <returns>The values that need to be add to the particle values to get the value given in the parameter.</returns> public override float[] DistanceToValue(float othervalue) { float[] res = new float[this.Count]; for (int i = 0; i < this.Count; i++) { res[i] = (float)AngleMath.SmallesAngle(this.ValuesVector[i], othervalue); } return(res); }
public static Coordinates.Spherical From(Coordinates.Cartesian3D point) { var r = Sqrt(Pow(point.X, 2) + Pow(point.Y, 2) + Pow(point.Z, 2)); var phi = AngleMath.Atan2(point.Y, point.X); var theta = AngleMath.Atan2(Sqrt(Pow(point.X, 2) + Pow(point.Y, 2)), point.Z); return(new Coordinates.Spherical( phi: phi, theta: theta, r: r)); }
/// <summary> /// Pointwise adds an array of values to the existing values. /// </summary> /// <param name="valuesToAdd">List of the values to add.</param> public override void AddToValues(float[] valuesToAdd) { if (valuesToAdd.Length != this.Count) { throw new ArgumentException("Length of input array is not the same as the particle count"); } Vector <float> res = new DenseVector(this.Count); this.ValuesVector.MapIndexed((index, value) => AngleMath.Sum(value, valuesToAdd[index]), res); this.Values = res.ToArray(); }
public void FixedUpdate() { var player = GameObject.FindGameObjectWithTag("Player"); if (player) { var playerPosition = player.transform.position; var diff = playerPosition - firePoint.position; var angle = AngleMath.VectorToAngle2D(diff); transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); } }
private void OnTouchMoving(Object sender, MotionEventArgs eventArgs) { float horizontalRotation = horizontalRotatingSpeed * eventArgs.motion.x; transform.Rotate(0, horizontalRotation, 0, Space.World); float verticalRotation = verticalRotatingSpeed * -eventArgs.motion.y; m_currentVerticalRotation += verticalRotation; Vector3 t_newEuler = transform.localEulerAngles; t_newEuler.x = AngleMath.ClampAngle(m_currentVerticalRotation, minVerticalRotation, maxVerticalRotation); transform.localEulerAngles = t_newEuler; }
public void TestResultWithRealData() { List <float> diffx = new List <float>(); List <float> diffy = new List <float>(); List <float> diffz = new List <float>(); for (int ts = 1; ts < 10001; ts += 33) { Vector3 res = this.filter.Calculate(ts); diffx.Add((float)AngleMath.SmallesAngle(res.X, (float)this.OriX(ts))); diffy.Add((float)AngleMath.SmallesAngle(res.Y, (float)this.Oriy(ts))); diffz.Add((float)AngleMath.SmallesAngle(res.Z, (float)this.Oriz(ts))); Console.WriteLine($"{this.OriX(ts)}, {this.Oriy(ts)},{this.Oriz(ts)}, {res.X},{res.Y},{res.Z}"); } Assert.True(diffx.Max() < 5 * this.orinoise.Maximum); Assert.True(diffx.Min() > 5 * this.orinoise.Minimum); Assert.True(diffy.Max() < 5 * this.orinoise.Maximum); Assert.True(diffy.Min() > 5 * this.orinoise.Minimum); Assert.True(diffz.Max() < 5 * this.orinoise.Maximum); Assert.True(diffz.Min() > 5 * this.orinoise.Minimum); }
public override void Fire() { Transform[] bullets = new Transform[perCircle]; for (int i = 0; i < perCircle; i++) { bullets[i] = Instantiate(bullet); float altAngle = (2 * Mathf.PI) / (float)perCircle / (float)spiraling * alt; Vector3 bulletVec = AngleMath.AngleToVector3(((2 * Mathf.PI) / (float)perCircle) * i + altAngle); bulletVec = bulletVec * bulletSpeed; bullets[i].transform.position = transform.position; bullets[i].GetComponent <UpdateBullet>().movement = bulletVec; } alt++; if (alt > spiraling) { alt = 1; } }
public void TestResultWithRealData2() { this.orisource.Setup(foo => foo.GetOrientationClosestTo(It.IsAny <long>(), It.IsAny <long>())).Returns <long, long>((ts, range) => this.Ori2(ts)); this.orisource2.Setup(foo => foo.GetOrientationClosestTo(It.IsAny <long>(), It.IsAny <long>())).Returns <long, long>((ts, range) => this.Ori2(ts)); List <float> diffx = new List <float>(); List <float> diffy = new List <float>(); List <float> diffz = new List <float>(); for (int ts = 1; ts < 10001; ts += 33) { Vector3 res = this.filter.Calculate(ts); diffx.Add((float)AngleMath.SmallesAngle(res.X, 180)); diffy.Add((float)AngleMath.SmallesAngle(res.Y, 0)); diffz.Add((float)AngleMath.SmallesAngle(res.Z, 180)); } Assert.True(diffx.Max() < 5 * this.orinoise.Maximum); Assert.True(diffx.Min() > 5 * this.orinoise.Minimum); Assert.True(diffy.Max() < 5 * this.orinoise.Maximum); Assert.True(diffy.Min() > 5 * this.orinoise.Minimum); Assert.True(diffz.Max() < 5 * this.orinoise.Maximum); Assert.True(diffz.Min() > 5 * this.orinoise.Minimum); }
void FixedUpdate() { Vector2 mousePositionInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition); var diff = mousePositionInWorld - (Vector2)(transform.position + gunPointerOffset); //if (diff.sqrMagnitude < MinTargetDistance * MinTargetDistance) //{ // diff = mousePositionInWorld - (Vector2)transform.position; //} if (mousePositionInWorld.x < transform.position.x) { transform.localScale = new Vector3(1, -1, 1); } else { transform.localScale = Vector3.one; } var angle = AngleMath.VectorToAngle2D(diff); transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); }
public void TestConvertPiRadianAngleToDegree() { Assert.Equal(180.0, AngleMath.RadianToDegree(Math.PI), 5); }
public void TestConvert3PiOver2RadianAngleToDegree() { Assert.Equal(270.0, AngleMath.RadianToDegree((3.0 * Math.PI) / 2.0), 5); }
public void TestConvert2PiRadianAngleToDegree() { Assert.Equal(360.0, AngleMath.RadianToDegree(2.0 * Math.PI), 5); }
public void TestComputeCosineOf90Degree() { Assert.Equal(0.0, AngleMath.CosineOfDegree(90.0), 5); }
/// <summary> /// Calculates the weighted average based on the current particle _values and corresponding weights. /// </summary> /// <returns>The weighted average weights of the particles.</returns> public override float WeightedAverage() { return(AngleMath.WeightedAverage(this.ValuesVector.ToArray(), this.WeightsVector.ToArray())); }
public void TestWeightedAverage() { Assert.AreEqual(0, AngleMath.WeightedAverage(new[] { 90f, 315 }, new float[] { 1f, (float)Math.Sqrt(2) }), 0.001); }
public void TestAverage() { Assert.AreEqual(5f, AngleMath.Average(new[] { 350f, 20f }), 0.0001); }
public void LargeNegativeNumbers() { Assert.AreEqual(360f - 45f, AngleMath.AngleClamp360(-360f - 360f - 45f)); }
public void LargePositiveNumbers() { Assert.AreEqual(45f, AngleMath.AngleClamp360(360f + 360f + 45f)); Assert.AreEqual(45f, AngleMath.AngleClamp360((10f * 360f) + 45f)); Assert.AreEqual(69f, AngleMath.AngleClamp360(360f + 360f + 69f)); }
public void TestConvertPiOver2RadianAngleToDegree() { Assert.Equal(90.0, AngleMath.RadianToDegree(Math.PI / 2.0), 5); }
public void TestSmallestAngle() { Assert.AreEqual(30, AngleMath.SmallesAngle(350f, 20f)); }
public void WeightedAverageNaNTest() { Assert.AreEqual(float.NaN, AngleMath.WeightedAverage(new float[] { 0 }, new float[] { 0 })); }
public void TestWeightedAverageWrongLength() { Assert.Throws <ArgumentException>(() => AngleMath.WeightedAverage(new[] { 1f }, new[] { 2f, 2f })); }
public void TestComputeCosineOf180Degree() { Assert.Equal(-1.0, AngleMath.CosineOfDegree(180.0), 5); }
public void TestAverageAround180() { Assert.AreEqual(180, AngleMath.Average(new float[] { 180, 181, 182, 183, 184, 185, 179, 178, 177, 176, 175 })); }
public void TestSum() { Assert.AreEqual(10, AngleMath.Sum(new[] { 350f, 20f })); }
public void Test1() { Assert.AreEqual(145f, AngleMath.AngleClamp360(145f)); Assert.AreEqual(30f, AngleMath.AngleClamp360(390f)); Assert.AreEqual(330f, AngleMath.AngleClamp360(-30f)); }
public void TestConvert360DegreesAngleToRadian() { Assert.Equal(2.0 * Math.PI, AngleMath.DegreeToRadian(360.0), 5); }