Beispiel #1
0
        /// <summary>
        /// Zwiêksza odleg³oœæ punktu od punktu (0,0), nie zmieniaj¹c k¹ta nachylenia.
        /// </summary>
        /// <param name="length">D³ugoœæ o jak¹ ma byæ przesuniêty punkt.</param>
        public void Extend(float length)
        {
            //tworzê wektor o kierunku zgodnym z danym punktem i d³ugoœci¹ lenght
            PointD addVector = new PointD(Math.Cos(Angle) * length, Math.Sin(Angle) * length);

            Move(addVector);
        }
        //    *
        //	 * Builds a shape from control points
        //
        //-----------------------------------------------------------------------
        public Path realizePath()
        {
            Path  helix      = new Path();
            float angleStep  = Math.TWO_PI / (float)(mNumSegPath);
            float heightStep = mHeight / (float)(mNumSegPath);

            for (int i = 0; i < mNumRound * mNumSegPath; i++)
            {
                helix.addPoint(mRadius * Math.Cos(angleStep * i), heightStep * i, mRadius * Math.Sin(angleStep * i));
            }

            return(helix);
        }
        /// Builds the shape
        public Shape realizeShape()
        {
            Radian alpha = Math.ACos((mLengthB * mLengthB + mLengthC * mLengthC - mLengthA * mLengthA) / (2 * mLengthB * mLengthC));

            Shape s = new Shape();

            s.addPoint(0.0f, 0.0f);
            s.addPoint(Math.Cos(alpha) * mLengthB, Math.Sin(alpha) * mLengthB);
            s.addPoint(mLengthC, 0.0f);
            s.close();
            s.translate((Math.Cos(alpha) * mLengthB + mLengthC) / -3.0f, mLengthB / -3.0f);

            return(s);
        }
Beispiel #4
0
        /// <summary>
        /// Obraca punkt o kat angle wzgledem punktu rotateCenter.
        /// </summary>
        /// <param name="rotateCenter">Srodek obrotu</param>
        /// <param name="angle">Kat o ktory, chcemy obrocic (podany w radianach).</param>
        /// <author>Emil</author>
        public void Rotate(PointD rotateCenter, float angle)
        {
            if (rotateCenter == this)
            {
                return;
            }
            //mX = (mX - rotateCenter.mX) * Math.Cos(angle) + rotateCenter.mX - (mY - rotateCenter.mY) * Math.Sin(angle);
            //mY = (mX - rotateCenter.mX) * Math.Sin(angle) + (mY - rotateCenter.mY) * Math.Cos(angle) + rotateCenter.mY;

            Move(-1 * rotateCenter);
            float oldX = mX,
                  oldY = mY;

            mX = oldX * Math.Cos(angle) - oldY * Math.Sin(angle);
            mY = oldX * Math.Sin(angle) + oldY * Math.Cos(angle);
            Move(rotateCenter);
        }
Beispiel #5
0
 protected float cosf(float a)
 {
     return(Math.Cos(a));
 }
Beispiel #6
0
 /// <summary>
 /// Rotates the specified vector clockwise by the specified angle, in radians
 /// </summary>
 /// <param name="vec">The vector2 to rotate</param>
 /// <param name="radians">The number of radians to rotate clockwise by</param>
 /// <returns>The rotated vector</returns>
 public static Vector2 RotateVector2(Vector2 vec, float rad)
 {
     return(new Vector2(vec.x * Math.Cos(rad) + vec.y * Math.Sin(rad), vec.x * Math.Sin(rad) - vec.y * Math.Cos(rad)));
 }
Beispiel #7
0
        private double interpolate(double x1, double x2, double a)
        {
            double f = (1 - Math.Cos((float)a * Math.PI)) * 0.5;

            return(x1 * (1 - f) + x2 * f);
        }
        //-----------------------------------------------------------------------
        //typedef std::vector<PathCoordinate> PathIntersection;
        public static void _extrudeIntersectionImpl(ref TriangleBuffer buffer, std_vector <MultiPath.PathCoordinate> intersection, MultiPath multiPath, Shape shape, Track shapeTextureTrack)
        {
            Vector3    intersectionLocation = multiPath.getPath((int)intersection[0].pathIndex).getPoint((int)intersection[0].pointIndex);
            Quaternion firstOrientation     = Utils._computeQuaternion(multiPath.getPath((int)intersection[0].pathIndex).getDirectionBefore((int)intersection[0].pointIndex));
            Vector3    refX = firstOrientation * Vector3.UNIT_X;
            Vector3    refZ = firstOrientation * Vector3.UNIT_Z;

            std_vector <Vector2> v2s = new std_vector <Vector2>();
            std_vector <MultiPath.PathCoordinate> coords = new std_vector <MultiPath.PathCoordinate>();
            std_vector <float> direction = new std_vector <float>();

            for (int i = 0; i < intersection.size(); ++i)
            {
                Path path       = multiPath.getPath((int)intersection[i].pathIndex);
                int  pointIndex = (int)intersection[i].pointIndex;
                if (pointIndex > 0 || path.isClosed())
                {
                    Vector3 vb  = path.getDirectionBefore(pointIndex);
                    Vector2 vb2 = new Vector2(vb.DotProduct(refX), vb.DotProduct(refZ));
                    v2s.push_back(vb2);
                    coords.push_back(intersection[i]);
                    direction.push_back(1);
                }
                if (pointIndex < path.getSegCount() || path.isClosed())
                {
                    Vector3 va  = -path.getDirectionAfter(pointIndex);
                    Vector2 va2 = new Vector2(va.DotProduct(refX), va.DotProduct(refZ));
                    v2s.push_back(va2);
                    coords.push_back(intersection[i]);
                    direction.push_back(-1);
                }
            }

            std_map <Radian, int> angles = new std_map <Radian, int>();

            for (int i = 1; i < v2s.Count; ++i)
            {
                //angles[Utils.angleTo(v2s[0], v2s[i])] = i;
                angles.insert(Utils.angleTo(v2s[0], v2s[i]), i);
            }
            std_vector <int> orderedIndices = new std_vector <int>();

            orderedIndices.push_back(0);
            //for (std_map<Radian, int>.Enumerator it = angles.begin(); it != angles.end(); ++it)
            foreach (var it in angles)
            {
                orderedIndices.push_back(it.Value);
            }
            for (int i = 0; i < orderedIndices.size(); ++i)
            {
                int    idx         = orderedIndices[i];
                int    idxBefore   = orderedIndices[Utils.modulo(i - 1, orderedIndices.Count)];
                int    idxAfter    = orderedIndices[Utils.modulo(i + 1, orderedIndices.Count)];
                Radian angleBefore = (Utils.angleBetween(v2s[idx], v2s[idxBefore]) - (Radian)Math.PI) / 2;
                Radian angleAfter  = ((Radian)Math.PI - Utils.angleBetween(v2s[idx], v2s[idxAfter])) / 2;

                int  pointIndex = (int)((int)coords[idx].pointIndex - direction[idx]);
                Path path       = multiPath.getPath((int)coords[idx].pathIndex);

                Quaternion qStd      = Utils._computeQuaternion(path.getAvgDirection(pointIndex) * direction[idx]);
                float      lineicPos = 0f;
                float      uTexCoord = path.getLengthAtPoint(pointIndex) / path.getTotalLength();

                // Shape making the joint with "standard extrusion"
                _extrudeShape(ref buffer, shape, path.getPoint(pointIndex), qStd, qStd, 1.0f, 1.0f, 1.0f, shape.getTotalLength(), uTexCoord, true, shapeTextureTrack);

                // Modified shape at the intersection
                Quaternion q = new Quaternion();
                if (direction[idx] > 0f)
                {
                    q = Utils._computeQuaternion(path.getDirectionBefore((int)coords[idx].pointIndex));
                }
                else
                {
                    q = Utils._computeQuaternion(-path.getDirectionAfter((int)coords[idx].pointIndex));
                }
                Quaternion qLeft      = q * new Quaternion(angleBefore, Vector3.UNIT_Y);
                Quaternion qRight     = q * new Quaternion(angleAfter, Vector3.UNIT_Y);
                float      scaleLeft  = 1.0f / Math.Abs(Math.Cos(angleBefore));
                float      scaleRight = 1.0f / Math.Abs(Math.Cos(angleAfter));

                uTexCoord = path.getLengthAtPoint((int)coords[idx].pointIndex) / path.getTotalLength();
                _extrudeShape(ref buffer, shape, path.getPoint((int)coords[idx].pointIndex), qLeft, qRight, 1.0f, scaleLeft, scaleRight, shape.getTotalLength(), uTexCoord, false, shapeTextureTrack);
            }
        }
 private float cosf(float p)
 {
     return(Math.Cos(p));
 }
Beispiel #10
0
        // Rotates a Vector2 by a given oriented angle
        public static Vector2 rotateVector2(Vector2 @in, Radian angleR)
        {
            float angle = angleR.ValueRadians;

            return(new Vector2(@in.x * (float)Math.Cos(angle) - @in.y * (float)Math.Sin(angle), @in.x * (float)Math.Sin(angle) + @in.y * (float)Math.Cos(angle)));
        }
 private float cos(float p)
 {
     return(Math.Cos(p));//throw new NotImplementedException();
 }