示例#1
0
        private static (Point centre, double radius, double angle) GetPinchValues(List <Point> locations)
        {
            if (locations.Count < 2)
            {
                throw new ArgumentException();
            }

            double centerX = 0;
            double centerY = 0;

            foreach (var location in locations)
            {
                centerX += location.X;
                centerY += location.Y;
            }

            centerX = centerX / locations.Count;
            centerY = centerY / locations.Count;

            var radius = Algorithms.Distance(centerX, centerY, locations[0].X, locations[0].Y);

            var angle = Math.Atan2(locations[1].Y - locations[0].Y, locations[1].X - locations[0].X) * 180.0 / Math.PI;

            return(new Point(centerX, centerY), radius, angle);
        }
示例#2
0
 /// <summary>
 /// Converts a direction cosine matrix to yaw, pitch, roll in radians.
 /// </summary>
 /// <param name="dcm">
 /// The direction cosine matrix.
 /// </param>
 /// <returns>
 /// The corresponding yaw, pitch, roll in radians.
 /// </returns>
 public static vec3f Dcm2YprInRads(mat3f dcm)
 {
     return(new vec3f(
                (float)SMath.Atan2(dcm.E01, dcm.E00),
                (float)SMath.Asin(-dcm.E02),
                (float)SMath.Atan2(dcm.E12, dcm.E22)));
 }
示例#3
0
        public static float Yaw(QuaternionF quat)
        {
            //Contract.Requires<ArgumentNullException>(quat != null, "quat");

            return((float)SysMath.Atan2(
                       2.0f * (quat._w * quat._z + quat._x * quat._y),
                       1.0f - 2.0f * (quat._y * quat._y + quat._z * quat._z)));
        }
示例#4
0
        public static float DefineAngle(Vec2 start, Vec2 end)
        {
            //позиция мыши
            float angle = (float)(Math.Atan2(end.Y - start.Y, end.X - start.X) / Math.PI * 180);

            angle = (angle < 0) ? angle + 360 : angle;

            return(angle);
        }
示例#5
0
        public static double GetAngle(Point center, Point endPoint)
        {
            var result = M.Atan2(endPoint.Y - center.Y, endPoint.X - center.X);

            if (result < 0)
            {
                result += 2 * PI;
            }
            return(result);
        }
        private void Apply3DImpl(AudioListener listener, AudioEmitter emitter)
        {
            // Since android has no function available to perform sound 3D localization by default, here we try to mimic the behaviour of XAudio2

            // After an analysis of the XAudio2 left/right stereo balance with respect to 3D world position,
            // it could be found the volume repartition is symmetric to the Up/Down and Front/Back planes.
            // Moreover the left/right repartition seems to follow a third degree polynomial function:
            // Volume_left(a) = 2(c-1)*a^3 - 3(c-1)*a^2 + c*a , where c is a constant close to c = 1.45f and a is the angle normalized bwt [0,1]
            // Volume_right(a) = 1-Volume_left(a)

            // As for signal attenuation wrt distance the model follows a simple inverse square law function as explained in XAudio2 documentation
            // ( http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.x3daudio.x3daudio_emitter(v=vs.85).aspx )
            // Volume(d) = 1                    , if d <= ScaleDistance where d is the distance to the listener
            // Volume(d) = ScaleDistance / d    , if d >= ScaleDistance where d is the distance to the listener

            // 1. Attenuation due to distance.
            var vecListEmit       = emitter.Position - listener.Position;
            var distListEmit      = vecListEmit.Length();
            var attenuationFactor = distListEmit <= emitter.DistanceScale ? 1f : emitter.DistanceScale / distListEmit;

            // 2. Left/Right balance.
            var repartRight = 0.5f;
            var worldToList = Matrix.Identity;
            var rightVec    = Vector3.Cross(listener.Forward, listener.Up);

            worldToList.Column1 = new Vector4(rightVec, 0);
            worldToList.Column2 = new Vector4(listener.Forward, 0);
            worldToList.Column3 = new Vector4(listener.Up, 0);
            var vecListEmitListBase  = Vector3.TransformNormal(vecListEmit, worldToList);
            var vecListEmitListBase2 = (Vector2)vecListEmitListBase;

            if (vecListEmitListBase2.Length() > 0)
            {
                const float c         = 1.45f;
                var         absAlpha  = Math.Abs(Math.Atan2(vecListEmitListBase2.Y, vecListEmitListBase2.X));
                var         normAlpha = (float)(absAlpha / (Math.PI / 2));
                if (absAlpha > Math.PI / 2)
                {
                    normAlpha = 2 - normAlpha;
                }
                repartRight = 0.5f * (2 * (c - 1) * normAlpha * normAlpha * normAlpha - 3 * (c - 1) * normAlpha * normAlpha * normAlpha + c * normAlpha);
                if (absAlpha > Math.PI / 2)
                {
                    repartRight = 1 - repartRight;
                }
            }

            // Set the volumes.
            localizationChannelVolumes = new[] { attenuationFactor *(1f - repartRight), attenuationFactor *repartRight };
            UpdateStereoVolumes();

            // 3. Calculation of the Doppler effect
            ComputeDopplerFactor(listener, emitter);
            UpdatePitch();
        }
示例#7
0
        public double Angle(TVec a, TVec b)
        {
            //return (this.Angle(b) - this.Angle(a));
            // http://stackoverflow.com/questions/2150050/finding-signed-angle-between-vectors
            double ax = a.X.ToDouble();
            double ay = a.Y.ToDouble();
            double bx = b.X.ToDouble();
            double by = b.Y.ToDouble();

            return(SysMath.Atan2(ax * by - ay * bx, ax * bx + ay * by));
        }
示例#8
0
        public bool IsClockWise(Vector2 pointA, Vector2 pointB, Vector2 pointC)
        {
            var v1x = pointB.X - pointC.X;
            var v1y = pointB.Y - pointC.Y;
            var v2x = pointA.X - pointC.X;
            var v2y = pointA.Y - pointC.Y;

            var angle = Math.Atan2(v1x, v1y) - Math.Atan2(v2x, v2y);

            return(angle >= Math.PI || angle < 0);
        }
示例#9
0
        public static double GetAngle(Vector2D vector, bool asRadian = true)
        {
            var result = SysMath.Atan2(vector.Y, vector.X);

            if (!asRadian)
            {
                return(AsAngle(result));
            }

            return(result);
        }
示例#10
0
        private static double Angle(MotionEvent me)
        {
            if (me.PointerCount < 2)
            {
                throw new ArgumentException();
            }
            var x        = me.GetX(0) - me.GetX(1);
            var y        = me.GetY(0) - me.GetY(1);
            var rotation = Math.Atan2(me.GetY(1) - me.GetY(0), me.GetX(1) - me.GetX(0)) * 180.0 / Math.PI;

            return(rotation);
        }
示例#11
0
        public static double GetAngle(Vector2D p1, Vector2D p2, bool asRadian = true)
        {
            double xDiff = p2.X - p1.X;
            double yDiff = p2.Y - p1.Y;

            if (asRadian)
            {
                return(SysMath.Atan2(yDiff, xDiff));
            }
            else
            {
                return(AsAngle(SysMath.Atan2(yDiff, xDiff)));
            }
        }
示例#12
0
        public static double GetAngle(double x1, double x2, double y1, double y2, bool asRadian = true)
        {
            double xDiff = x2 - x1;
            double yDiff = y2 - y1;

            if (asRadian)
            {
                return(SysMath.Atan2(yDiff, xDiff));
            }
            else
            {
                return(AsAngle(SysMath.Atan2(yDiff, xDiff)));
            }
        }
示例#13
0
        /// <summary>
        /// Return the angle between the 2 2D (X, Y) vectors in radian from -PI to +PI.
        /// </summary>
        public static float Angle2D(Vector3 v1, Vector3 v2)
        {
            double angle = CSharpMath.Atan2(v2.Y, v2.X) - CSharpMath.Atan2(v1.Y, v1.X);

            if (angle > CSharpMath.PI)
            {
                angle -= (CSharpMath.PI * 2.0);
            }
            else if (angle < (0.0 - CSharpMath.PI))
            {
                angle += (CSharpMath.PI * 2.0);
            }
            return((float)angle);
        }
示例#14
0
        public void Atan2誤差1パーセント以下の精度で計算できる()
        {
            void assertYX(T y, T x)
            {
                var t1 = Table.Atan2(y, x);
                var t2 = M.Atan2(y, x);

                Assert.True(M.Abs(t1 - t2) < 2e-3);
            }

            void assert(T theta)
            {
                var(y, x) = (M.Cos(theta), M.Sin(theta));
                assertYX(y, x);
            }

            var r = new Random();

            for (int i = 0; i < 1000; i++)
            {
                var theta = r.NextDouble() * 1000 - 500;
                assert(theta);
            }
            for (int i = 0; i < 1000; i++)
            {
                var y = r.NextDouble() * 1000 - 500;
                var x = r.NextDouble() * 1000 - 500;
                assertYX(y, x);
            }

            foreach (var theta in _cornerCase)
            {
                assert(theta);
            }

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    assertYX(x, y);
                }
            }
        }
示例#15
0
        public bool Intersect(Planet planet)
        {
            var distance    = (float)Math.Sqrt(Math.Pow(planet.Transform.X - Transform.X, 2) + Math.Pow(planet.Transform.Y - Transform.Y, 2));
            var totalRadius = Radius + planet.Radius;

            if (distance <= totalRadius && planet.IsCheck == false)
            {
                var angle = (float)Math.Atan2(Transform.Y - planet.Transform.Y, Transform.X - planet.Transform.X);
                angle += (float)Math.PI / 2 - planet.Transform.Angle;

                //    planet.AngularVelocity = 0.04f;
                planet.CorrectAngle = -angle;
                //    planet.Angle = angle;
                planet.IsCheck = true;
                SetPlanet(planet);

                ((GameScreen)_engine.Screens.CurrentScreen).LayoutTop.IncrementBalls();
                IncrementBalls?.Invoke(null, null);
                return(true);
            }

            return(false);
        }
示例#16
0
        /// <summary>
        /// Busca el desarrollo de la clotoide cuya tangente es <c>v</c>: DClotho x v = 0.
        /// Por simetria, existen 2 soluciones, el desarrollo positivo y el negativo.
        /// </summary>
        public static double FindTangent(bool invertY, double a, Vector2d v)
        {
            int ysign = (invertY ? -1 : 1);

            return(SysMath.Sqrt(2 * a * a * SysMath.Atan2(ysign * v.Y, v.X)));
        }
示例#17
0
 public static Half Atan2(Half x,
                          Half y) =>
 (Half)M.Atan2(y, x);
示例#18
0
文件: Math.cs 项目: zjloscar/Dynamo
 public static double Atan2(double value1, double value2)
 {
     return(CSMath.Atan2(value1, value2) * kRadiansToDegrees);
 }
示例#19
0
 public static Angle Atan2(Real y, Real x)
 {
     return(FromRadians(Math.Atan2(y, x)));
 }
示例#20
0
 /// <summary>
 ///     Finds the inverse tangent of quotient of two numbers. Returns the angle
 ///     whose tangent is the ratio: numerator/denominator.
 /// </summary>
 /// <param name="numerator">The numerator of the tangent of the angle.</param>
 /// <param name="denominator">The denominator of the tangent of the angle.</param>
 /// <returns name="angle">The angle whose tangent is numerator/denominator.</returns>
 /// <search>atangent,arctangent</search>
 public static double Atan2(double numerator, double denominator)
 {
     return(CSMath.Atan2(numerator, denominator) * kRadiansToDegrees);
 }
示例#21
0
 /// <summary>
 /// Calculates an angle out of given coordinates.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 public static float ToAngle(float x, float y)
 {
     return((float)Math.Atan2(y, x) + MathHelper.Pi);
 }
示例#22
0
 public float GetAngle()
 {
     return((float)Math.Atan2(Y, X));
 }
示例#23
0
 public static float Yaw(QuaternionF quat)
 {
     return((float)SysMath.Atan2(
                2.0f * (quat._w * quat._z + quat._x * quat._y),
                1.0f - 2.0f * (quat._y * quat._y + quat._z * quat._z)));
 }
示例#24
0
 public static float Roll(QuaternionF quat)
 {
     return((float)SysMath.Atan2(
                2.0f * (quat._w * quat._x + quat._y * quat._z),
                1.0f - 2.0f * (quat._x * quat._x + quat._y * quat._y)));
 }
示例#25
0
 /// <summary>
 /// Sets the Angle by using a direction vector.
 /// </summary>
 /// <param name="direction">The direction vector.</param>
 public void SetDirectionVector(Vector direction)
 {
     ClockwiseRadians = NMath.Atan2(direction.Ycomponent, direction.Xcomponent);
 }
示例#26
0
 /*public T Angle(TVec v)
  * {
  *  return math.Atan2(v.Y, v.X);
  * }*/
 public double Angle(TVec v)
 {
     return(SysMath.Atan2(v.Y.ToDouble(), v.X.ToDouble()));
 }
 public static double Atan2(double y, double x)
 => Math.Atan2(y, x);
示例#28
0
 public float GetAngle2(Branch branch)
 {
     return((float)Math.Atan2(Y - branch.Y, X - branch.X));
 }
示例#29
0
 public static float Atan2(float x, float y)
 {
     return((float)XMath.Atan2(x, y));
 }
示例#30
0
 public static double Atan2(double y, double x)
 {
     return(Math.Atan2(y, x));
 }