Example #1
0
        /// <summary>
        /// From the virtual math museum
        /// </summary>
        public static Vector3D Dini2(Vector3D disk)
        {
            Vector3D uv = DiskToUpper(disk);
            double   u  = Math.Log(uv.Y);
            //double v = DonHatch.acosh( 1 + ( Math.Pow( uv.X, 2 ) + 0 ) / ( 2 * Math.Pow( uv.Y, 2 ) ) ) ;
            //if( uv.X < 0 )
            //	v *= -1;
            double v = uv.X;

            if (u <= -4 || u > 4 ||
                v < -6 * Math.PI || v > 6 * Math.PI)
            {
                return(Infinity.InfinityVector);
            }

            double psi = 0.5;

            psi *= Math.PI;
            double sinpsi = Math.Sin(psi);
            double cospsi = Math.Cos(psi);
            double g      = (u - cospsi * v) / sinpsi;
            double s      = Math.Exp(g);
            double r      = (2 * sinpsi) / (s + 1 / s);
            double t      = r * (s - 1 / s) * 0.5;

            return(new Vector3D(u - t, r * Math.Cos(v), r * Math.Sin(v)));
        }
Example #2
0
        /// <summary>
        /// Returns the cosecant of the specified angle.
        /// Returns <see cref="double.NegativeInfinity" /> if angle is a multiple of -π or +2π.
        /// Returns <see cref="double.PositiveInfinity" /> if 0 or angle is a multiple of +π or -2π.
        /// </summary>
        /// <param name="radians">The angle in radians.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns>System.Double.</returns>
        public static double Csc(double radians, double tolerance = Numbers.ZeroTolerance)
        {
            if (NMath.Abs(radians).IsZeroSign())
            {
                return(double.PositiveInfinity);
            }
            if (radians.IsEqualTo(Numbers.Pi, tolerance))
            {
                return(double.PositiveInfinity);
            }                                                                                       // 180 deg
            if (radians.IsEqualTo(Numbers.TwoPi, tolerance))
            {
                return(double.NegativeInfinity);
            }                                                                                       // 360 deg
            if (radians.IsEqualTo(-Numbers.Pi, tolerance))
            {
                return(double.NegativeInfinity);
            }                                                                                       // -180 deg
            if (radians.IsEqualTo(-Numbers.TwoPi, tolerance))
            {
                return(double.PositiveInfinity);
            }                                                                                       // -360 deg

            return(1d / NMath.Sin(radians));
        }
Example #3
0
        public static Vec2 Rotate(this Vec2 v, float angle)
        {
            var x = v.X * (float)Math.Cos(angle) - v.Y * (float)Math.Sin(angle);
            var y = v.X * (float)Math.Sin(angle) + v.Y * (float)Math.Cos(angle);

            return(new Vec2(x, y));
        }
Example #4
0
        /// <summary>
        /// Create a hue filter matrix using the given angle in degrees.
        /// </summary>
        /// <param name="degrees">The angle of rotation in degrees.</param>
        /// <returns>The <see cref="Matrix4x4"/></returns>
        public static Matrix4x4 CreateHueFilter(float degrees)
        {
            // Wrap the angle round at 360.
            degrees = degrees % 360;

            // Make sure it's not negative.
            while (degrees < 0)
            {
                degrees += 360;
            }

            float radian    = MathFExtensions.DegreeToRadian(degrees);
            float cosRadian = (float)MathF.Cos(radian);
            float sinRadian = (float)MathF.Sin(radian);

            // The matrix is set up to preserve the luminance of the image.
            // See http://graficaobscura.com/matrix/index.html
            // Number are taken from https://msdn.microsoft.com/en-us/library/jj192162(v=vs.85).aspx
            return(new Matrix4x4
            {
                M11 = .213F + (cosRadian * .787F) - (sinRadian * .213F),
                M12 = .213F - (cosRadian * .213F) - (sinRadian * 0.143F),
                M13 = .213F - (cosRadian * .213F) - (sinRadian * .787F),
                M21 = .715F - (cosRadian * .715F) - (sinRadian * .715F),
                M22 = .715F + (cosRadian * .285F) + (sinRadian * 0.140F),
                M23 = .715F - (cosRadian * .715F) + (sinRadian * .715F),
                M31 = .072F - (cosRadian * .072F) + (sinRadian * .928F),
                M32 = .072F - (cosRadian * .072F) - (sinRadian * 0.283F),
                M33 = .072F + (cosRadian * .928F) + (sinRadian * .072F),
                M44 = 1
            });
        }
        public IPhysicsBody CreateCannonBall(int x, int y, double angle, double velocity, ICollider cannonBall)
        {
            var vx = Math.Cos((angle) * Math.PI / 180) * velocity;
            var vy = Math.Sin((angle) * Math.PI / 180) * velocity;

            var offvx = Math.Cos((angle) * Math.PI / 180) * 4d * 16d;
            var offvy = Math.Sin((angle) * Math.PI / 180) * 3d * 16d;



            var fixDef = new FixtureDef();

            fixDef.density     = 1;
            fixDef.friction    = 1;
            fixDef.restitution = .6;
            var bodyDef = new BodyDef();

            bodyDef.type       = BodyType.DYNAMIC;
            bodyDef.position.x = this.PixelToMeter(x + offvx);
            bodyDef.position.y = this.PixelToMeter(y + offvy);

            var circleShape = new CircleShape();

            circleShape.m_radius = 1.25d / 2d;

            fixDef.shape = circleShape;

            var body    = this.World.createBody(bodyDef);
            var fixture = body.createFixture(fixDef);

            body.setUserData(cannonBall);
            body.applyLinearImpulse(new Vec2(vx, vy), body.getWorldCenter());

            return(new PhysicsBody(body));
        }
Example #6
0
        /// <summary>
        /// This will calculate the Mobius transform that represents an isometry in the given geometry.
        /// The isometry will rotate CCW by angle A about the origin, then translate the origin to P (and -P to the origin).
        /// </summary>
        public void Isometry(Geometry g, double angle, Complex P)
        {
            // As Don notes in the hypebolic case:
            // Any isometry of the Poincare disk can be expressed as a complex function of z of the form:
            // (T*z + P)/(1 + conj(P)*T*z), where T and P are complex numbers, |P| < 1 and |T| = 1.
            // This indicates a rotation by T around the origin followed by moving the origin to P (and -P to the origin).
            //
            // I figured out that the other cases can be handled with simple variations of the C coefficients.
            Complex T = new Complex(Math.Cos(angle), Math.Sin(angle));

            A = T;
            B = P;
            D = 1;

            switch (g)
            {
            case Geometry.Spherical:
            {
                C = Complex.Conjugate(P) * T * -1;
                break;
            }

            case Geometry.Euclidean:
            {
                C = 0;
                break;
            }

            case Geometry.Hyperbolic:
            {
                C = Complex.Conjugate(P) * T;
                break;
            }
            }
        }
Example #7
0
        public void Process(float[] data)
        {
            for (int i = 0, length = data.Length; i < length; i += 2)
            {
                float left  = 0;
                float right = 0;

                for (int j = firstActiveVoice; j != -1; j = voices[j].next)
                {
                    float envelopeGain = voices[j].envelope.gain;
                    voices[j].envelope.AdvanceTime(sampleRateRecip);
                    float value = envelopeGain * (float)Math.Sin(voices[j].time * voices[j].freq * Table.Pi2);
                    left           += value * voices[j].gainLeft;
                    right          += value * voices[j].gainRight;
                    voices[j].time += sampleRateRecip;
                }

                data[i]     = left;
                data[i + 1] = right;

                                #if MIDIF_DEBUG_VISUALIZER
                WaveVisualizer.Push(0, left);
                                #endif
            }

            Panic();
        }
Example #8
0
        public static double ElasticInOut(double b, double c, double t, double d = 1)
        {
            if (t == 0)
            {
                return(b);
            }
            if ((t /= d / 2) == 2)
            {
                return(b + c);
            }
            double s;
            double a = c;
            double p = d * (.3 * 1.5);

            if (a < Math.Abs(c))
            {
                a = c;
                s = p / 4;
            }
            else
            {
                s = p / (2 * Math.PI) * Math.Asin(c / a);
            }
            if (t < 1)
            {
                return(-.5 * (a * Math.Pow(2, 10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b);
            }
            return(a * Math.Pow(2, -10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b);
        }
Example #9
0
        public static Polygon[] BuildDuoprism(int num)
        {
            double angleInc = 2 * Math.PI / num;

            // Torus in two directions.
            List <Polygon> polys  = new List <Polygon>();
            double         angle1 = angleInc / 2;

            for (int i = 0; i < num; i++)
            {
                double angle2 = angleInc / 2;
                for (int j = 0; j < num; j++)
                {
                    List <Vector3D> polyPoints = new List <Vector3D>();

                    polyPoints.Add(new Vector3D(
                                       Math.Cos(angle2),
                                       Math.Sin(angle2),
                                       Math.Cos(angle1),
                                       Math.Sin(angle1)));

                    polyPoints.Add(new Vector3D(
                                       Math.Cos(angle2),
                                       Math.Sin(angle2),
                                       Math.Cos(angle1 + angleInc),
                                       Math.Sin(angle1 + angleInc)));

                    polyPoints.Add(new Vector3D(
                                       Math.Cos(angle2 + angleInc),
                                       Math.Sin(angle2 + angleInc),
                                       Math.Cos(angle1 + angleInc),
                                       Math.Sin(angle1 + angleInc)));

                    polyPoints.Add(new Vector3D(
                                       Math.Cos(angle2 + angleInc),
                                       Math.Sin(angle2 + angleInc),
                                       Math.Cos(angle1),
                                       Math.Sin(angle1)));

                    Polygon poly = new Polygon();
                    poly.CreateEuclidean(polyPoints.ToArray());
                    polys.Add(poly);

                    angle2 += angleInc;
                }
                angle1 += angleInc;
            }

            // Nice starting orientation.
            Matrix4D m1 = Matrix4D.MatrixToRotateinCoordinatePlane(Math.PI / 8, 0, 2);
            Matrix4D m2 = Matrix4D.MatrixToRotateinCoordinatePlane(-Math.PI / 4, 1, 2);

            foreach (Polygon poly in polys)
            {
                poly.Rotate(m1);
                poly.Rotate(m2);
            }

            return(polys.ToArray());
        }
Example #10
0
        // NOTE: angle should be in radians.
        public void RotateAboutAxis(Vector3D axis, double angle)
        {
            // normalize the axis
            axis.Normalize();
            double _x = axis.X;
            double _y = axis.Y;
            double _z = axis.Z;

            // build the rotation matrix - I got this from http://www.makegames.com/3dRotation/
            double c = Math.Cos(angle);
            double s = -1 * Math.Sin(angle);
            double t = 1 - c;

            double[,] mRot = new double[, ]
            {
                { t *_x *_x + c, t *_x *_y - s *_z, t *_x *_z + s *_y },
                { t *_x *_y + s *_z, t *_y *_y + c, t *_y *_z - s *_x },
                { t *_x *_z - s *_y, t *_y *_z + s *_x, t *_z *_z + c },
            };

            double x = this.X;
            double y = this.Y;
            double z = this.Z;

            // do the multiplication
            this = new Vector3D(
                mRot[0, 0] * x + mRot[1, 0] * y + mRot[2, 0] * z,
                mRot[0, 1] * x + mRot[1, 1] * y + mRot[2, 1] * z,
                mRot[0, 2] * x + mRot[1, 2] * y + mRot[2, 2] * z);
        }
Example #11
0
        /// <summary>
        /// Spherically interpolates between a and b by factor. The parameter factor is not clamped.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="factor"></param>
        /// <returns></returns>
        public static Quaternion SlerpUnclamped(Quaternion a, Quaternion b, float factor)
        {
            if (a.magnitudeSquared == 0.0f)
            {
                if (b.magnitudeSquared == 0.0f)
                {
                    return(Identity);
                }
                return(b);
            }
            else if (b.magnitudeSquared == 0.0)
            {
                return(a);
            }

            float invX, invY, invZ, invW;

            float cosHalfAngle = a.w * b.w + Vector3.Dot(a.Axis, b.Axis);

            if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f)
            {
                return(a);
            }
            else if (cosHalfAngle < 0.0f)
            {
                invX = -b.x;
                invY = -b.y;
                invZ = -b.z;
                invW = -b.w;

                cosHalfAngle = -cosHalfAngle;
            }

            float blendA, blendB;

            if (cosHalfAngle < 0.99f)
            {
                float halfAngle           = (float)Maths.Acos(cosHalfAngle);
                float sinHalfAngle        = (float)Maths.Sin(halfAngle);
                float oneOverSinHalfAngle = 1.0f / sinHalfAngle;
                blendA = (float)Maths.Sin(halfAngle * (1.0f - factor)) * oneOverSinHalfAngle;
                blendB = (float)Maths.Sin(halfAngle * factor) * oneOverSinHalfAngle;
            }
            else
            {
                blendA = 1.0f - factor;
                blendB = factor;
            }

            Quaternion result = new Quaternion(blendA * a.Axis + blendB, blendA * a.w + blendB + b.w);

            if (result.magnitudeSquared > 0.0f)
            {
                return(Normalize(result));
            }
            else
            {
                return(Identity);
            }
        }
Example #12
0
        /// <summary>
        /// Spherically interpolates between a and b by a factor.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="factor"></param>
        /// <returns></returns>
        public static Quaternion Slerp(Quaternion a, Quaternion b, float factor)
        {
            float x, y, z, w;
            float opposite, inverse;
            var   dot = Dot(a, b);

            if (Maths.Abs(dot) > (1.0 - Mathf.Epsilon))
            {
                inverse  = 1.0f - factor;
                opposite = factor * Maths.Sign(dot);
            }
            else
            {
                var acos       = (float)Maths.Acos(Maths.Abs(dot));
                var inverseSin = (float)(1.0 / Maths.Sin(acos));

                inverse  = (float)(Maths.Sin((1.0f - factor) * acos) * inverseSin);
                opposite = (float)(Maths.Sin(factor * acos) * inverseSin * Maths.Sign(dot));
            }

            x = (inverse * a.X) + (opposite * b.X);
            y = (inverse * a.Y) + (opposite * b.Y);
            z = (inverse * a.Z) + (opposite * b.Z);
            w = (inverse * a.W) + (opposite * b.W);

            return(new Quaternion(x, y, z, w));
        }
Example #13
0
            public void Set(Table table, float fc, float q)
            {
                // Console.Log("\tfilter set fc", this.fc , "->", fc, "q", this.q, "->", q);
                this.fc = fc;
                this.q  = q;

                // https://github.com/FluidSynth/fluidsynth/blob/29c668683f43e3b8b4aab0b8aa73cb02aacd6fcb/src/rvoice/fluid_iir_filter.c#L382
                // filter will defunct in 22050Hz sample rate
                float maxFc = .45f * table.sampleRate;

                if (fc > maxFc)
                {
                    fc = maxFc;
                }
                else if (fc < 5)
                {
                    fc = 5;
                }

                gain = 1.0 / Math.Sqrt(q);

                // https://github.com/FluidSynth/fluidsynth/blob/29c668683f43e3b8b4aab0b8aa73cb02aacd6fcb/src/rvoice/fluid_iir_filter.c#L278
                // previous simple bipolar lowpass is faulty when fc is large and should not be used:
                // http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
                double omega   = Table.Pi2 * fc * table.sampleRateRecip;
                double sin     = Math.Sin(omega);
                double cos     = Math.Cos(omega);
                double alpha   = sin / (2f * q);
                double a0Recip = 1f / (1 + alpha);

                a1 = -2f * cos * a0Recip;
                a2 = (1f - alpha) * a0Recip;
                b1 = (1f - cos) * a0Recip * gain;
                b2 = b1 * .5f;
            }
Example #14
0
        public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
        {
            //  Roll first, about axis the object is facing, then
            //  pitch upward, then yaw to face into the new heading
            float sr, cr, sp, cp, sy, cy;

            float halfRoll = roll * 0.5f;

            sr = (float)SM.Sin(halfRoll); cr = (float)SM.Cos(halfRoll);

            float halfPitch = pitch * 0.5f;

            sp = (float)SM.Sin(halfPitch); cp = (float)SM.Cos(halfPitch);

            float halfYaw = yaw * 0.5f;

            sy = (float)SM.Sin(halfYaw); cy = (float)SM.Cos(halfYaw);

            Quaternion result;

            result.X = cy * sp * cr + sy * cp * sr;
            result.Y = sy * cp * cr - cy * sp * sr;
            result.Z = cy * cp * sr - sy * sp * cr;
            result.W = cy * cp * cr + sy * sp * sr;

            return(result);
        }
Example #15
0
        public void AddSphere(Vector3 position, float size, Color4 color)
        {
            // Compute our step around each circle
            float step = GameUtils.TwoPi / 32;

            // Create the loop on the XY plane first
            for (float a = 0f; a < GameUtils.TwoPi; a += step)
            {
                AddLine(position + new Vector3((float)Math.Cos(a), (float)Math.Sin(a), 0f) * size,
                        position + new Vector3((float)Math.Cos(a + step), (float)Math.Sin(a + step), 0f) * size, color);
            }

            // Next on the XZ plane
            for (float a = 0f; a < GameUtils.TwoPi; a += step)
            {
                AddLine(position + new Vector3((float)Math.Cos(a), 0f, (float)Math.Sin(a)) * size,
                        position + new Vector3((float)Math.Cos(a + step), 0f, (float)Math.Sin(a + step)) * size, color);
            }

            // Finally on the YZ plane
            for (float a = 0f; a < GameUtils.TwoPi; a += step)
            {
                AddLine(position + new Vector3(0f, (float)Math.Cos(a), (float)Math.Sin(a)) * size,
                        position + new Vector3(0f, (float)Math.Cos(a + step), (float)Math.Sin(a + step)) * size, color);
            }
        }
Example #16
0
        public static double ElasticOut(double b, double c, double t, double d = 1)
        {
            if (t == 0)
            {
                return(b);
            }
            if ((t /= d) == 1)
            {
                return(b + c);
            }
            double s;
            double a = c;
            double p = d * .3;

            if (a < Math.Abs(c))
            {
                a = c;
                s = p / 4;
            }
            else
            {
                s = p / (2 * Math.PI) * Math.Asin(c / a);
            }
            return(a * Math.Pow(2, -10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p) + c + b);
        }
Example #17
0
        /// <summary>
        /// Returns the midpoint of our polygon edge on the sphere.
        /// </summary>
        private Vector3D MidPoint(double inRadius, double faceRadius)
        {
            // Using info from:
            // http://en.wikipedia.org/wiki/Tetrahedron
            // http://eusebeia.dyndns.org/4d/tetrahedron

            // XXX - Should make this method just work in all {p,q,r} cases!

            // tet
            //double vertexToFace = Math.Acos( 1.0 / 3 );  // 338

            // icosa
            double polyCircumRadius = Math.Sin(2 * Math.PI / 5);
            double polyInRadius     = Math.Sqrt(3) / 12 * (3 + Math.Sqrt(5));

            // cube
            //double polyCircumRadius = Math.Sqrt( 3 );
            //double polyInRadius = 1;

            double vertexToFace = Math.Acos(polyInRadius / polyCircumRadius);
            double angleTemp    = Math.Acos(RBall / (inRadius + faceRadius));

            double angleToRotate = (Math.PI - vertexToFace) - angleTemp;

            angleToRotate = vertexToFace - angleTemp;

            Vector3D zVec = new Vector3D(0, 0, 1);

            zVec.RotateAboutAxis(new Vector3D(0, 1, 0), angleToRotate);
            return(zVec);
        }
Example #18
0
        /// <summary>
        /// Rotate CCW in the XY plane by an angle in radians.
        /// </summary>
        public void RotateXY(double angle)
        {
            double component1 = X;
            double component2 = Y;

            X = Math.Cos(angle) * component1 - Math.Sin(angle) * component2;
            Y = Math.Sin(angle) * component1 + Math.Cos(angle) * component2;
        }
Example #19
0
        /// <summary>
        /// Calculates the maximum latitude of a great circle path from origin location in direction of bearing angle
        /// <para>using Clairaut’s formula</para>
        /// </summary>
        /// <param name="origin">origin location in geographic degrees</param>
        /// <param name="bearing">bearing from origin in geographic degrees</param>
        public static double GetLatitudeMax(IGeoLocatable origin, double bearing)
        {
            origin  = origin.ToRadians();
            bearing = bearing.ToRadians();
            var latMax = Math.Acos(Math.Abs(Math.Sin(bearing) * Math.Cos(origin.Latitude)));

            return(latMax);
        }
        /// <summary>
        /// Converts to cylindrical coordinates.
        /// </summary>
        /// <returns>CylindricalCoordinate.</returns>
        public static CylindricalCoordinate ToCylindrical(SphericalCoordinate coordinate)
        {
            double radius  = coordinate.Radius * NMath.Sin(coordinate.Inclination.Radians);
            double height  = coordinate.Radius * NMath.Cos(coordinate.Inclination.Radians);
            double azimuth = coordinate.Azimuth.Radians;

            return(new CylindricalCoordinate(radius, height, azimuth, coordinate.Tolerance));
        }
        private Vec2 CalcPoleEndPos(Body poleBody)
        {
            // Determine position of top of pole relative to its center of mass.
            float angle = poleBody.GetAngle();
            Vec2  polePosTopRelative = new Vec2(__ArmLength * (float)-SysMath.Sin(angle), __ArmLength * (float)SysMath.Cos(angle));

            return(poleBody.GetPosition() + (polePosTopRelative * 0.5f));
        }
        /// <summary>
        /// Converts to Cartesian coordinates.
        /// </summary>
        /// <returns>CartesianCoordinate.</returns>
        public static CartesianCoordinate3D ToCartesian(SphericalCoordinate coordinate)
        {
            double x = coordinate.Radius * NMath.Sin(coordinate.Inclination.Radians) * NMath.Cos(coordinate.Azimuth.Radians);
            double y = coordinate.Radius * NMath.Sin(coordinate.Inclination.Radians) * NMath.Sin(coordinate.Azimuth.Radians);
            double z = coordinate.Radius * NMath.Cos(coordinate.Inclination.Radians);

            return(new CartesianCoordinate3D(x, y, z, coordinate.Tolerance));
        }
Example #23
0
        private static void HopfFibration(Tiling tiling)
        {
            int       segDivisions    = 10;
            int       circleDivisions = 125;
            Shapeways mesh            = new Shapeways();

            HashSet <Vector3D> done = new HashSet <Vector3D>();

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    if (done.Contains(seg.Midpoint))
                    {
                        continue;
                    }

                    // Subdivide the segment, and project points to S2.
                    Vector3D[] points = seg.Subdivide(segDivisions).Select(v => Spherical2D.PlaneToSphere(v)).ToArray();
                    foreach (Vector3D point in points)
                    {
                        // Get the hopf circle and add to mesh.
                        // http://en.wikipedia.org/wiki/Hopf_fibration#Explicit_formulae
                        double a      = point.X;
                        double b      = point.Y;
                        double c      = point.Z;
                        double factor = 1 / (Math.Sqrt(1 + c));
                        if (Tolerance.Equal(c, -1))
                        {
                            continue;
                        }

                        List <Vector3D> circlePoints = new List <Vector3D>();
                        double          angleInc     = 2 * Math.PI / circleDivisions;
                        double          angle        = 0;
                        for (int i = 0; i <= circleDivisions; i++)
                        {
                            double sinTheta = Math.Sin(angle);
                            double cosTheta = Math.Cos(angle);
                            circlePoints.Add(new Vector3D(
                                                 (1 + c) * cosTheta,
                                                 a * sinTheta - b * cosTheta,
                                                 a * cosTheta + b * sinTheta,
                                                 (1 + c) * sinTheta));

                            angle += angleInc;
                        }

                        bool shrink = false;
                        ProjectAndAddS3Points(mesh, circlePoints.ToArray(), shrink);
                    }

                    done.Add(seg.Midpoint);
                }
            }

            STL.SaveMeshToSTL(mesh.Mesh, @"D:\p4\R3\sample\out1.stl");
        }
Example #24
0
        public static Vector3D Dini(Vector3D uv, double a, double b)
        {
            uv = DiskToUpper(uv);

            // Eq 1.86 on p36 of book Backlund and Darboux Transformations
            double eta = Math.PI / 2 - Math.PI / 20;
            //double eta = Math.PI / 2;
            double p = 1;                    // curvature
            double x = DonHatch.acosh(uv.Y); // Used info on mathworld for tractrix to figure this out.
            //double x = DonHatch.acosh( Math.Exp( DonHatch.acosh( ( uv.Y * uv.Y + 1 ) / ( 2 * uv.Y ) ) ) );
            //double x = Math.Log( uv.Y );
            double y = uv.X;

            double pSinEta = p * Math.Sin(eta);
            double chi     = (x - y * Math.Cos(eta)) / pSinEta;

            if (x <= -4 || x > 4 ||
                y < -3 * Math.PI || y > 3 * Math.PI)
            {
                return(Infinity.InfinityVector);
            }

            Vector3D result = new Vector3D(
                pSinEta * Sech(chi) * Math.Cos(y / p),
                pSinEta * Sech(chi) * Math.Sin(y / p),
                x - pSinEta * Math.Tanh(chi));

            return(result);

            /*
             * System.Func<double, Complex> tractrix = new System.Func<double, Complex>(
             * ( t ) =>
             * {
             *      //return new Complex( t - Math.Tanh( t ), 1.0 / Math.Cosh( t ) );
             *      return new Complex( - Math.Sqrt( 1 - 1 / (t*t) ) + DonHatch.acosh( t ), 1.0 / t );
             * } );
             *
             * double logy = Math.Log( uv.Y );
             * //Complex tract = tractrix( logy );
             * Complex tract = tractrix( uv.Y );
             * return new Vector3D(
             *      a * Math.Cos( uv.X ) * tract.Imaginary,
             *      a * Math.Sin( uv.X ) * tract.Imaginary,
             *      a * tract.Real + b * uv.X );
             */

            /*
             * return new Vector3D(
             *      a * Math.Cos( uv.X ) / Math.Cosh( uv.Y ),
             *      a * Math.Sin( uv.X ) / Math.Cosh( uv.Y ),
             *      a * (uv.Y - Math.Tanh( uv.Y )) + b * uv.X ); */

            /*return new Vector3D(
             *      a * Math.Cos( uv.X ) * Math.Sin( uv.Y ),
             *      a * Math.Sin( uv.X ) * Math.Sin( uv.Y ),
             *      a * (Math.Cos( uv.Y ) + Math.Log( Math.Tan( 0.5 * uv.Y ) )) + b * uv.X );*/
        }
Example #25
0
        public static Transform2 Rotate(double r)
        {
            double c = SysMath.Cos(r);
            double s = SysMath.Sin(r);

            return(new Transform2Matrix(
                       c, -s, 0,
                       s, c, 0));
        }
Example #26
0
        public static Transform2 Rotate(double px, double py, double r)
        {
            double c = SysMath.Cos(r);
            double s = SysMath.Sin(r);

            return(new Transform2Matrix(
                       c, -s, -px * c + py * s + px,
                       s, c, -px * s - py * c + py));
        }
Example #27
0
        public static Vec2 RotateGrad(this Vec2 v, float angle, float radius)
        {
            angle /= 180 * (float)Math.PI;

            var x = v.X * (float)Math.Cos(angle) * radius - v.Y * (float)Math.Sin(angle) * radius;
            var y = v.X * (float)Math.Sin(angle) * radius + v.Y * (float)Math.Cos(angle) * radius;

            return(new Vec2(x, y));
        }
Example #28
0
        private (double width, double height) GetBoundingBoxOfRotatedRectangle(double rotation, double width, double height)
        {
            if (rotation == 0)
            {
                return(width, height);
            }
            var rot = Astrometry.ToRadians(rotation);

            return(Math.Abs(width * Math.Sin(rot) + height * Math.Cos(rot)), Math.Abs(height * Math.Sin(rot) + width * Math.Cos(rot)));
        }
Example #29
0
 /// <summary>
 /// This is used as a check to make sure a divide by zero error is caught.
 /// </summary>
 /// <param name="x">The double to be evaluated.</param>
 /// <param name="SinValue">This is a out value. if true = -2 else it is Sin(x)</param>
 /// <returns>This returns true or false.</returns>
 public static bool TryCheckIfCosecantWillHaveADivideByZeroError(double x, out double SinValue)
 {
     if (MathObj.Sin(x) == 0)
     {
         SinValue = -2;
         return(true);
     }
     SinValue = MathObj.Sin(x);
     return(false);
 }
Example #30
0
        public static double EdgeLength(int p, int q, int r)
        {
            double pip = PiOverNSafe(p);
            double pir = PiOverNSafe(r);

            double pi_hqr     = Pi_hpq(q, r);
            double edgeLength = 2 * DonHatch.acosh(Math.Cos(pip) * Math.Sin(pir) / Math.Sin(pi_hqr));

            return(edgeLength);
        }