コード例 #1
0
        /// <summary>
        /// ITransformUpdaterのメンバーの実装
        /// </summary>
        public bool UpdateTransform()
        {
            UserTrackerFrameRef usrFrameRef = device.CurrentUserTrackerFrameRef;

            if (CurrentTrackUserId >= 0)
            {
                UserData[] usrs =
                    (from sk in usrFrameRef.Users where sk.UserId == CurrentTrackUserId select sk).ToArray();
                if (usrs.Length != 1)
                {
                    return(true);
                }
                Skeleton skeleton = usrs[0].Skeleton;
                if (skeleton.State == Skeleton.SkeletonState.TRACKED)
                {
                    trackTarget = skeleton;
                    if (TrackingUser != null)
                    {
                        TrackingUser(this, usrs[0]);
                    }
                    PMXBone       head         = getBone("頭");
                    PMXBone       neck         = getBone("首");
                    PMXBone       torso        = getBone("上半身");
                    PMXBone       r_shoulder   = getBone("右腕");
                    PMXBone       r_elbow      = getBone("右ひじ");
                    PMXBone       r_hand       = getBone("右手首");
                    PMXBone       r_hip        = getBone("右足");
                    PMXBone       r_knee       = getBone("右ひざ");
                    PMXBone       r_foot       = getBone("右足首");
                    PMXBone       l_shoulder   = getBone("左腕");
                    PMXBone       l_elbow      = getBone("左ひじ");
                    PMXBone       l_hand       = getBone("左手首");
                    PMXBone       l_hip        = getBone("左足");
                    PMXBone       l_knee       = getBone("左ひざ");
                    PMXBone       l_foot       = getBone("左足首");
                    SkeletonJoint sj_head      = skeleton.getJoint(SkeletonJoint.JointType.HEAD);
                    SkeletonJoint sj_neck      = skeleton.getJoint(SkeletonJoint.JointType.NECK);
                    SkeletonJoint sj_rShoulder = skeleton.getJoint(SkeletonJoint.JointType.RIGHT_SHOULDER);
                    SkeletonJoint sj_lShoulder = skeleton.getJoint(SkeletonJoint.JointType.LEFT_SHOULDER);
                    SkeletonJoint sj_rElbow    = skeleton.getJoint(SkeletonJoint.JointType.RIGHT_ELBOW);
                    SkeletonJoint sj_lElbow    = skeleton.getJoint(SkeletonJoint.JointType.LEFT_ELBOW);
                    SkeletonJoint sj_r_hand    = skeleton.getJoint(SkeletonJoint.JointType.RIGHT_HAND);
                    SkeletonJoint sj_l_hand    = skeleton.getJoint(SkeletonJoint.JointType.LEFT_HAND);
                    SkeletonJoint sj_torso     = skeleton.getJoint(SkeletonJoint.JointType.TORSO);
                    SkeletonJoint sj_rHip      = skeleton.getJoint(SkeletonJoint.JointType.RIGHT_HIP);
                    SkeletonJoint sj_lHip      = skeleton.getJoint(SkeletonJoint.JointType.LEFT_HIP);
                    SkeletonJoint sj_rKnee     = skeleton.getJoint(SkeletonJoint.JointType.RIGHT_KNEE);
                    SkeletonJoint sj_lKnee     = skeleton.getJoint(SkeletonJoint.JointType.LEFT_KNEE);
                    SkeletonJoint sj_rFoot     = skeleton.getJoint(SkeletonJoint.JointType.RIGHT_FOOT);
                    SkeletonJoint sj_lFoot     = skeleton.getJoint(SkeletonJoint.JointType.LEFT_FOOT);
                    //腰のひねり
                    Vector3 shoulder_l2r =
                        Vector3.Normalize(
                            ToVector3(sj_rShoulder.Position) -
                            ToVector3(sj_lShoulder.Position));
                    Vector3 hip_l2r =
                        Vector3.Normalize(
                            ToVector3(sj_rHip.Position) -
                            ToVector3(sj_lHip.Position));
                    //shoulder_l2r.Normalize();hip_l2r.Normalize();
                    float angle = (float)Math.Acos(Math.Min(Vector3.Dot(shoulder_l2r, hip_l2r), 1f));
                    torso.Rotation *= Quaternion.RotationAxis(new Vector3(0, 1, 0), angle);
                    torso.UpdateGrobalPose();
                    getRotation(neck, head, skeleton, sj_neck,
                                sj_head);
                    getRotation(r_shoulder, r_elbow, skeleton,
                                sj_rShoulder, sj_rElbow);
                    getRotation(r_elbow, r_hand, skeleton,
                                sj_rElbow,
                                sj_r_hand);
                    getRotation(l_shoulder, l_elbow, skeleton,
                                sj_lShoulder, sj_lElbow);
                    getRotation(l_elbow, l_hand, skeleton,
                                sj_lElbow, sj_l_hand);
                    getRotation(torso, neck, skeleton, sj_torso, sj_neck);
                    getRotation(r_hip, r_knee, skeleton,
                                sj_rHip, sj_rKnee);
                    getRotation(r_knee, r_foot, skeleton,
                                sj_rKnee, sj_rFoot);
                    getRotation(l_hip, l_knee, skeleton,
                                sj_lHip, sj_lKnee);
                    getRotation(l_knee, l_foot, skeleton,
                                sj_lKnee, sj_lFoot);
                }
            }
            return(true);
        }
コード例 #2
0
 public static Vector2 acos(Vector2 arg0)
 {
     return(new Vector2((float)(Math.Acos(arg0.x)), (float)(Math.Acos(arg0.y))));
 }
コード例 #3
0
        private List <Vector2f> PopulateNewDomainPoints3(CJStarDomain entity)
        {
            List <Vector2f> pointsToReturn = new List <Vector2f>();

            for (int i = 0; i < entity.Domain.Count; i++)
            {
                StarEntity currentStarEntity = entity.Domain[i];
                StarEntity nextStarEntity    = entity.Domain[(i + 1) % entity.Domain.Count];

                pointsToReturn.Add(currentStarEntity.Position);

                if (entity.DomainLinks.TryGetValue(currentStarEntity, out StarLinkEntity currentLink) && currentLink is CurvedStarLinkEntity)
                {
                    int sign = currentLink.StarFrom == currentStarEntity ? 1 : -1;

                    float radiusLink = (currentLink as CurvedStarLinkEntity).Radius * sign;

                    Vector2f currentToNextNorm = nextStarEntity.Position - currentStarEntity.Position;
                    float    lenCurrentToNext  = currentToNextNorm.Len();
                    currentToNextNorm = currentToNextNorm / lenCurrentToNext;

                    float angleToRotate = (float)Math.Acos(lenCurrentToNext / (2 * radiusLink));

                    Vector2f currentToCenter = currentToNextNorm.Rotate(angleToRotate) * radiusLink;
                    Vector2f centerPoint     = currentStarEntity.Position + currentToCenter;

                    Vector2f newPoint = centerPoint + (-currentToCenter).Rotate(Math.Sign(radiusLink) * sign * (Math.PI / 2 - angleToRotate));

                    pointsToReturn.Add(newPoint);
                }
                else
                {
                    Vector2f firstPoint;
                    if (i == 0)
                    {
                        firstPoint = entity.Domain[entity.Domain.Count - 1].Position;
                    }
                    else
                    {
                        firstPoint = entity.Domain[i - 1].Position;
                    }
                    Vector2f secondPoint = entity.Domain[i].Position;
                    Vector2f thirdPoint  = entity.Domain[(i + 1) % entity.Domain.Count].Position;
                    Vector2f fourthPoint = entity.Domain[(i + 2) % entity.Domain.Count].Position;

                    Vector2f normVector1 = secondPoint - firstPoint;
                    normVector1 = normVector1 / normVector1.Len();

                    Vector2f normVector2 = thirdPoint - secondPoint;
                    normVector2 = normVector2 / normVector2.Len();

                    Vector2f normVector3 = fourthPoint - thirdPoint;
                    normVector3 = normVector3 / normVector3.Len();

                    float distX1 = normVector1.X != 0 ? (secondPoint.X - firstPoint.X) / normVector1.X : (secondPoint.Y - firstPoint.Y) / normVector1.Y;
                    float distX2 = normVector2.X != 0 ? distX1 + (thirdPoint.X - secondPoint.X) / normVector2.X : distX1 + (thirdPoint.Y - secondPoint.Y) / normVector2.Y;
                    float distX3 = normVector3.X != 0 ? distX2 + (fourthPoint.X - thirdPoint.X) / normVector3.X : distX2 + (fourthPoint.Y - thirdPoint.Y) / normVector3.Y;

                    Vector2f firstPointX  = new Vector2f(0, firstPoint.X);
                    Vector2f secondPointX = new Vector2f(distX1, secondPoint.X);
                    Vector2f thirdPointX  = new Vector2f(distX2, thirdPoint.X);
                    Vector2f fourthPointX = new Vector2f(distX3, fourthPoint.X);

                    float x         = (distX2 + distX1) / 2;
                    float newPointX = this.CubicInterpolate(x, firstPointX, secondPointX, thirdPointX, fourthPointX);

                    Vector2f firstPointY  = new Vector2f(0, firstPoint.Y);
                    Vector2f secondPointY = new Vector2f(distX1, secondPoint.Y);
                    Vector2f thirdPointY  = new Vector2f(distX2, thirdPoint.Y);
                    Vector2f fourthPointY = new Vector2f(distX3, fourthPoint.Y);

                    float newPointY = this.CubicInterpolate(x, firstPointY, secondPointY, thirdPointY, fourthPointY);

                    pointsToReturn.Add(new Vector2f(newPointX, newPointY));
                }
            }

            return(pointsToReturn);
        }
コード例 #4
0
        /// <summary>
        ///   <para>Returns the angle in degrees between two rotations a and b.</para>
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public static float AngleBetween(this Quaternion <float> a, Quaternion <float> b)
        {
            float single = a.Dot(b);

            return((float)Math.Acos(Math.Min(Math.Abs(single), 1f)) * 2f * 57.29578f);
        }
コード例 #5
0
 public static float ACos(float v)
 {
     return((float)Math.Acos(v));
 }
コード例 #6
0
ファイル: Mathd.cs プロジェクト: Ramminus/SpaceGame
 public static double Acos(double d)
 {
     return(Math.Acos(d));
 }
コード例 #7
0
ファイル: Evaluation.cs プロジェクト: pwitvoet/mess
 public static double acos(double cosine) => Math.Acos(cosine);
コード例 #8
0
ファイル: MikktspaceContext.cs プロジェクト: Sookhaal/Materia
        static STSpace EvalTspace(List <int> face_indices, int iFaces, int[] piTriListIn, ref STriInfo[] pTriInfos, ref SMikkTSpaceContext context, int iVertexRepresentitive)
        {
            STSpace res       = new STSpace();
            float   fAngleSum = 0;
            int     face      = 0;

            res.vOs   = Vector3.Zero;
            res.vOt   = Vector3.Zero;
            res.fMagS = 0; res.fMagT = 0;

            for (face = 0; face < iFaces; face++)
            {
                int f = face_indices[face];

                if ((pTriInfos[f].iFlag & GROUP_WITH_ANY) == 0)
                {
                    Vector3 n, vOs, vOt, p0, p1, p2, v1, v2;
                    float   fCos, fAngle, fMagS, fMagT;
                    int     i = -1, index = -1, i0 = -1, i1 = -1, i2 = -1;
                    if (piTriListIn[3 * f] == iVertexRepresentitive)
                    {
                        i = 0;
                    }
                    else if (piTriListIn[3 * f + 1] == iVertexRepresentitive)
                    {
                        i = 1;
                    }
                    else if (piTriListIn[3 * f + 2] == iVertexRepresentitive)
                    {
                        i = 2;
                    }

                    index = piTriListIn[3 * f + i];

                    n   = GetNormal(ref context, index);
                    vOs = pTriInfos[f].vOs - (Vector3.Dot(n, pTriInfos[f].vOs) * n);
                    vOt = pTriInfos[f].vOt - (Vector3.Dot(n, pTriInfos[f].vOt) * n);
                    if (VNotZero(ref vOs))
                    {
                        vOs.Normalize();
                    }
                    if (VNotZero(ref vOt))
                    {
                        vOt.Normalize();
                    }

                    i2 = piTriListIn[3 * f + (i < 2 ? (i + 1) : 0)];
                    i1 = piTriListIn[3 * f + i];
                    i0 = piTriListIn[3 * f + (i > 0 ? (i - 1) : 2)];

                    p0 = GetPosition(ref context, i0);
                    p1 = GetPosition(ref context, i1);
                    p2 = GetPosition(ref context, i2);

                    v1 = p0 - p1;
                    v2 = p2 - p1;

                    v1 = v1 - Vector3.Dot(n, v1) * n;
                    v2 = v2 - Vector3.Dot(n, v2) * n;
                    if (VNotZero(ref v1))
                    {
                        v1.Normalize();
                    }
                    if (VNotZero(ref v2))
                    {
                        v2.Normalize();
                    }

                    fCos   = Vector3.Dot(v1, v2); fCos = fCos > 1 ? 1 : (fCos < -1 ? -1 : fCos);
                    fAngle = (float)Math.Acos(fCos);
                    fMagS  = pTriInfos[f].fMagS;
                    fMagT  = pTriInfos[f].fMagT;

                    res.vOs    = res.vOs + vOs * fAngle;
                    res.vOt    = res.vOt + vOt * fAngle;
                    res.fMagS += (fAngle * fMagS);
                    res.fMagT += (fAngle * fMagT);

                    fAngleSum += fAngle;
                }
            }

            if (VNotZero(ref res.vOs))
            {
                res.vOs.Normalize();
            }
            if (VNotZero(ref res.vOt))
            {
                res.vOt.Normalize();
            }

            if (fAngleSum > 0)
            {
                res.fMagS /= fAngleSum;
                res.fMagT /= fAngleSum;
            }

            return(res);
        }
コード例 #9
0
 private static int math_acos(lua_State L)
 {
     lua_pushnumber(L, Math.Acos(luaL_checknumber(L, 1)));
     return(1);
 }
コード例 #10
0
 public static double AngleBetweenVectors(Vector v1, Vector v2)
 {
     return(Math.Acos((v1 * v2) / (v1.Length * v2.Length)) * 180 / Math.PI);
 }
コード例 #11
0
        /// <summary>Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as
        /// possible. The target is specified in the world coordinate system.</summary>
        /// <param name="child">A direct descendant of the parent bone.</param>
        static public void Apply(Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha)
        {
            if (alpha == 0)
            {
                child.UpdateWorldTransform();
                return;
            }
            //float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX;
            if (!parent.appliedValid)
            {
                parent.UpdateAppliedTransform();
            }
            if (!child.appliedValid)
            {
                child.UpdateAppliedTransform();
            }
            float px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, csx = child.ascaleX;
            int   os1, os2, s2;

            if (psx < 0)
            {
                psx = -psx;
                os1 = 180;
                s2  = -1;
            }
            else
            {
                os1 = 0;
                s2  = 1;
            }
            if (psy < 0)
            {
                psy = -psy;
                s2  = -s2;
            }
            if (csx < 0)
            {
                csx = -csx;
                os2 = 180;
            }
            else
            {
                os2 = 0;
            }
            float cx = child.ax, cy, cwx, cwy, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
            bool  u = Math.Abs(psx - psy) <= 0.0001f;

            if (!u)
            {
                cy  = 0;
                cwx = a * cx + parent.worldX;
                cwy = c * cx + parent.worldY;
            }
            else
            {
                cy  = child.ay;
                cwx = a * cx + b * cy + parent.worldX;
                cwy = c * cx + d * cy + parent.worldY;
            }
            Bone pp = parent.parent;

            a = pp.a;
            b = pp.b;
            c = pp.c;
            d = pp.d;
            float id = 1 / (a * d - b * c), x = targetX - pp.worldX, y = targetY - pp.worldY;
            float tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;

            x = cwx - pp.worldX;
            y = cwy - pp.worldY;
            float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
            float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;

            if (u)
            {
                l2 *= psx;
                float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
                if (cos < -1)
                {
                    cos = -1;
                }
                else if (cos > 1)
                {
                    cos = 1;
                }
                a2 = (float)Math.Acos(cos) * bendDir;
                a  = l1 + l2 * cos;
                b  = l2 * (float)Math.Sin(a2);
                a1 = (float)Math.Atan2(ty * a - tx * b, tx * a + ty * b);
            }
            else
            {
                a = psx * l2;
                b = psy * l2;
                float aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = (float)Math.Atan2(ty, tx);
                c = bb * l1 * l1 + aa * dd - aa * bb;
                float c1 = -2 * bb * l1, c2 = bb - aa;
                d = c1 * c1 - 4 * c2 * c;
                if (d >= 0)
                {
                    float q = (float)Math.Sqrt(d);
                    if (c1 < 0)
                    {
                        q = -q;
                    }
                    q = -(c1 + q) / 2;
                    float r0 = q / c2, r1 = c / q;
                    float r = Math.Abs(r0) < Math.Abs(r1) ? r0 : r1;
                    if (r * r <= dd)
                    {
                        y  = (float)Math.Sqrt(dd - r * r) * bendDir;
                        a1 = ta - (float)Math.Atan2(y, r);
                        a2 = (float)Math.Atan2(y / psy, (r - l1) / psx);
                        goto outer;                         // break outer;
                    }
                }
                float minAngle = MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
                float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
                c = -a * l1 / (aa - bb);
                if (c >= -1 && c <= 1)
                {
                    c = (float)Math.Acos(c);
                    x = a * (float)Math.Cos(c) + l1;
                    y = b * (float)Math.Sin(c);
                    d = x * x + y * y;
                    if (d < minDist)
                    {
                        minAngle = c;
                        minDist  = d;
                        minX     = x;
                        minY     = y;
                    }
                    if (d > maxDist)
                    {
                        maxAngle = c;
                        maxDist  = d;
                        maxX     = x;
                        maxY     = y;
                    }
                }
                if (dd <= (minDist + maxDist) / 2)
                {
                    a1 = ta - (float)Math.Atan2(minY * bendDir, minX);
                    a2 = minAngle * bendDir;
                }
                else
                {
                    a1 = ta - (float)Math.Atan2(maxY * bendDir, maxX);
                    a2 = maxAngle * bendDir;
                }
            }
outer:
            float os = (float)Math.Atan2(cy, cx) * s2;
            float rotation = parent.arotation;

            a1 = (a1 - os) * MathUtils.RadDeg + os1 - rotation;
            if (a1 > 180)
            {
                a1 -= 360;
            }
            else if (a1 < -180)
            {
                a1 += 360;
            }
            parent.UpdateWorldTransform(px, py, rotation + a1 * alpha, parent.scaleX, parent.ascaleY, 0, 0);
            rotation = child.arotation;
            a2       = ((a2 + os) * MathUtils.RadDeg - child.ashearX) * s2 + os2 - rotation;
            if (a2 > 180)
            {
                a2 -= 360;
            }
            else if (a2 < -180)
            {
                a2 += 360;
            }
            child.UpdateWorldTransform(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
        }
コード例 #12
0
ファイル: MathHelper.cs プロジェクト: TomMalow/atc
 /// <summary>
 /// Returns the angle whose cosine is the specified number.
 /// </summary>
 /// <param name="value">A number representing a cosine, where -1 ≤d≤ 1.</param>
 public static double Acos(double value)
 {
     return(RadiansToDegrees(Math.Acos(value)));
 }
コード例 #13
0
ファイル: Lua.Libraries.cs プロジェクト: xiuzhifu/neolua
        }         // func abs

        public static double acos(double x)
        {
            return(Math.Acos(x));
        }         // func acos
コード例 #14
0
    /******************************************************************************
    *  Copyright (c) 2008-2009 Ryan Juckett
    *  http://www.ryanjuckett.com/
    *
    *  This software is provided 'as-is', without any express or implied
    *  warranty. In no event will the authors be held liable for any damages
    *  arising from the use of this software.
    *
    *  Permission is granted to anyone to use this software for any purpose,
    *  including commercial applications, and to alter it and redistribute it
    *  freely, subject to the following restrictions:
    *
    *  1. The origin of this software must not be misrepresented; you must not
    *    claim that you wrote the original software. If you use this software
    *    in a product, an acknowledgment in the product documentation would be
    *    appreciated but is not required.
    *
    *  2. Altered source versions must be plainly marked as such, and must not be
    *    misrepresented as being the original software.
    *
    *  3. This notice may not be removed or altered from any source
    *    distribution.
    ******************************************************************************/
    ///***************************************************************************************
    /// CalcIK_2D_TwoBoneAnalytic
    /// Given a two bone chain located at the origin (bone1 is the parent of bone2), this
    /// function will compute the bone angles needed for the end of the chain to line up
    /// with a target position. If there is no valid solution, the angles will be set to
    /// get as close to the target as possible.
    ///
    /// returns: True when a valid solution was found.
    ///***************************************************************************************
    public static bool CalcIK_2D_TwoBoneAnalytic
    (
        out double angle1,   // Angle of bone 1
        out double angle2,   // Angle of bone 2
        bool solvePosAngle2, // Solve for positive angle 2 instead of negative angle 2
        double length1,      // Length of bone 1. Assumed to be >= zero
        double length2,      // Length of bone 2. Assumed to be >= zero
        double targetX,      // Target x position for the bones to reach
        double targetY       // Target y position for the bones to reach
    )
    {
        Debug.Assert(length1 >= 0);
        Debug.Assert(length2 >= 0);

        const double epsilon = 0.0001; // used to prevent division by small numbers

        bool foundValidSolution = true;

        double targetDistSqr = (targetX * targetX + targetY * targetY);

        //===
        // Compute a new value for angle2 along with its cosine
        double sinAngle2;
        double cosAngle2;

        double cosAngle2_denom = 2 * length1 * length2;

        if (cosAngle2_denom > epsilon)
        {
            cosAngle2 = (targetDistSqr - length1 * length1 - length2 * length2)
                        / (cosAngle2_denom);

            // if our result is not in the legal cosine range, we can not find a
            // legal solution for the target
            if ((cosAngle2 < -1.0) || (cosAngle2 > 1.0))
            {
                foundValidSolution = false;
            }

            // clamp our value into range so we can calculate the best
            // solution when there are no valid ones
            cosAngle2 = Math.Max(-1, Math.Min(1, cosAngle2));

            // compute a new value for angle2
            angle2 = Math.Acos(cosAngle2);

            // adjust for the desired bend direction
            if (!solvePosAngle2)
            {
                angle2 = -angle2;
            }

            // compute the sine of our angle
            sinAngle2 = Math.Sin(angle2);
        }
        else
        {
            // At least one of the bones had a zero length. This means our
            // solvable domain is a circle around the origin with a radius
            // equal to the sum of our bone lengths.
            double totalLenSqr = (length1 + length2) * (length1 + length2);
            if (targetDistSqr < (totalLenSqr - epsilon) ||
                targetDistSqr > (totalLenSqr + epsilon))
            {
                foundValidSolution = false;
            }

            // Only the value of angle1 matters at this point. We can just
            // set angle2 to zero.
            angle2    = 0.0;
            cosAngle2 = 1.0;
            sinAngle2 = 0.0;
        }

        //===
        // Compute the value of angle1 based on the sine and cosine of angle2
        double triAdjacent = length1 + length2 * cosAngle2;
        double triOpposite = length2 * sinAngle2;

        double tanY = targetY * triAdjacent - targetX * triOpposite;
        double tanX = targetX * triAdjacent + targetY * triOpposite;

        // Note that it is safe to call Atan2(0,0) which will happen if targetX and
        // targetY are zero
        angle1 = Math.Atan2(tanY, tanX);

        return(foundValidSolution);
    }
コード例 #15
0
        static private String doFunc(String fun, double param)
        {
            switch (fun)
            {
            case "cos": return(Math.Cos(param).ToString());

            case "sin": return(Math.Sin(param).ToString());

            case "tg": if (Math.Abs(param % (2 * Math.PI)) == (Math.PI / 2))
                {
                    throw new TgException(param);
                }
                else
                {
                    return(Math.Tan(param).ToString());
                }

            case "asin": if (param < -1 || param > 1)
                {
                    throw new ArcSinCosException(param);
                }
                else
                {
                    return(Math.Asin(param).ToString());
                }

            case "acos": if (param < -1 || param > 1)
                {
                    throw new ArcSinCosException(param);
                }
                else
                {
                    return(Math.Acos(param).ToString());
                }

            case "atg": return(Math.Atan(param).ToString());

            case "sqrt": if (param < 0)
                {
                    throw new SqrtException(param);
                }
                else
                {
                    return(Math.Sqrt(param).ToString());
                }

            case "ln": if (param <= 0)
                {
                    throw new LogException(param);
                }
                else
                {
                    return(Math.Log(param).ToString());
                }

            case "lg": if (param <= 0)
                {
                    throw new LogException(param);
                }
                else
                {
                    return(Math.Log10(param).ToString());
                }

            default: return("");
            }
        }
コード例 #16
0
 public static float Acos(this float x)
 {
     return((float)Math.Acos(x));
 }
コード例 #17
0
ファイル: SlideGeometry.cs プロジェクト: a24ibrah/mac-samples
        private void BuildVisualizationsOfNode(SCNNode node, ref SCNNode verticesNode, ref SCNNode normalsNode)
        {
            // A material that will prevent the nodes from being lit
            var noLightingMaterial = SCNMaterial.Create();

            noLightingMaterial.LightingModelName = SCNLightingModel.Constant;

            var normalMaterial = SCNMaterial.Create();

            normalMaterial.LightingModelName = SCNLightingModel.Constant;
            normalMaterial.Diffuse.Contents  = NSColor.Red;

            // Create nodes to represent the vertex and normals
            var positionVisualizationNode = SCNNode.Create();
            var normalsVisualizationNode  = SCNNode.Create();

            // Retrieve the vertices and normals from the model
            var positionSource = node.Geometry.GetGeometrySourcesForSemantic(SCNGeometrySourceSemantic.Vertex) [0];
            var normalSource   = node.Geometry.GetGeometrySourcesForSemantic(SCNGeometrySourceSemantic.Normal) [0];

            // Get vertex and normal bytes
            var vertexBufferByte = (byte[])positionSource.Data.ToArray();
            var vertexBuffer     = new float[vertexBufferByte.Length / 4];

            Buffer.BlockCopy(vertexBufferByte, 0, vertexBuffer, 0, vertexBufferByte.Length);

            var normalBufferByte = (byte[])normalSource.Data.ToArray();
            var normalBuffer     = new float[normalBufferByte.Length / 4];

            Buffer.BlockCopy(normalBufferByte, 0, normalBuffer, 0, normalBufferByte.Length);

            // Iterate and create geometries to represent the positions and normals
            for (var i = 0; i < positionSource.VectorCount; i++)
            {
                // One new node per normal/vertex
                var vertexNode = SCNNode.Create();
                var normalNode = SCNNode.Create();

                // Attach one sphere per vertex
                var sphere = SCNSphere.Create(0.5f);
                sphere.SegmentCount  = 4;                // use a small segment count for better performances
                sphere.FirstMaterial = noLightingMaterial;
                vertexNode.Geometry  = sphere;

                // And one pyramid per normal
                var pyramid = SCNPyramid.Create(0.1f, 0.1f, 8);
                pyramid.FirstMaterial = normalMaterial;
                normalNode.Geometry   = pyramid;

                // Place the position node
                var componentsPerVector = positionSource.ComponentsPerVector;
                vertexNode.Position = new SCNVector3(vertexBuffer [i * componentsPerVector], vertexBuffer [i * componentsPerVector + 1], vertexBuffer [i * componentsPerVector + 2]);

                // Place the normal node
                normalNode.Position = vertexNode.Position;

                // Orientate the normal
                var up         = new Vector3(0, 0, 1);
                var normalVec  = new Vector3(normalBuffer [i * 3], normalBuffer [i * 3 + 1], normalBuffer [i * 3 + 2]);
                var axis       = Vector3.Normalize(Vector3.Cross(up, normalVec));
                var dotProduct = Vector3.Dot(up, normalVec);
                normalNode.Rotation = new SCNVector4(axis.X, axis.Y, axis.Z, (float)Math.Acos(dotProduct));

                // Add the nodes to their parent
                positionVisualizationNode.AddChildNode(vertexNode);
                normalsVisualizationNode.AddChildNode(normalNode);
            }

            // We must flush the transaction in order to make sure that the parametric geometries (sphere and pyramid)
            // are up-to-date before flattening the nodes
            SCNTransaction.Flush();

            // Flatten the visualization nodes so that they can be rendered with 1 draw call
            verticesNode = positionVisualizationNode.FlattenedClone();
            normalsNode  = normalsVisualizationNode.FlattenedClone();
        }
コード例 #18
0
ファイル: Mathf.cs プロジェクト: jlauener/MonoPunk
 public static float Acos(float value)
 {
     return((float)Math.Acos(value));
 }
コード例 #19
0
ファイル: Mathf.cs プロジェクト: Lanboost/LansUnityUIAdapter
 //
 // Summary:
 //     Returns the arc-cosine of f - the angle in radians whose cosine is f.
 //
 // Parameters:
 //   f:
 public static float Acos(float f)
 {
     return((float)Math.Acos(f));
 }
コード例 #20
0
ファイル: CGLM.cs プロジェクト: aortner/AgraBot
 //float functions
 public static float acos(float x)
 {
     return((float)Math.Acos(x));
 }
コード例 #21
0
ファイル: Sql.cs プロジェクト: zuiwanting/linq2db
 [Sql.Function] public static Double?Acos(Double?value)
 {
     return(value == null ? null : (Double?)Math.Acos(value.Value));
 }
コード例 #22
0
 public static R4 Acos(R4 a)
 {
     return((R4)Math.Acos(a));
 }
コード例 #23
0
        /// <summary>
        ///   <para>Returns the angle in degrees between two rotations a and b.</para>
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public static double AngleBetween(this Quaternion <double> a, Quaternion <double> b)
        {
            double single = a.Dot(b);

            return((double)Math.Acos(Math.Min(Math.Abs(single), 1d)) * 2d * 57.29578d);
        }
コード例 #24
0
ファイル: Mathf.cs プロジェクト: tasouza/godot-switch
 public static real_t Acos(real_t s)
 {
     return((real_t)Math.Acos(s));
 }
コード例 #25
0
 public static float acos(float arg0)
 {
     return((float)(Math.Acos(arg0)));
 }
コード例 #26
0
 private static float Angle(Quaternion a, Quaternion b)
 {
     return((float)(Math.Acos((double)Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2.0 * 57.2957801818848));
 }
コード例 #27
0
 public static Vector4 acos(Vector4 arg0)
 {
     return(new Vector4((float)(Math.Acos(arg0.x)), (float)(Math.Acos(arg0.y)), (float)(Math.Acos(arg0.z)), (float)(Math.Acos(arg0.w))));
 }
コード例 #28
0
 private static void Angle(ref Quaternion a, ref Quaternion b, out float result)
 {
     result = (float)(Math.Acos((double)Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2.0 * 57.2957801818848);
 }
コード例 #29
0
        // Updates motion laws, marker positions, etc.
        public override void UpdateTime(double mytime)
        {
            // First, inherit to parent class
            base.UpdateTime(mytime);

            // Move markers 1 and 2 to align them as gear teeth

            ChMatrix33 <double> ma1        = new ChMatrix33 <double>(0);
            ChMatrix33 <double> ma2        = new ChMatrix33 <double>(0);
            ChMatrix33 <double> mrotma     = new ChMatrix33 <double>(0);
            ChMatrix33 <double> marot_beta = new ChMatrix33 <double>(0);
            ChVector            mx;
            ChVector            my;
            ChVector            mz;
            ChVector            mr;
            ChVector            mmark1;
            ChVector            mmark2;
            ChVector            lastX;
            ChVector            vrota;
            ChCoordsys          newmarkpos = new ChCoordsys(new ChVector(0, 0, 0), new ChQuaternion(1, 0, 0, 0));

            ChFrame <double> abs_shaft1 = ChFrame <double> .FNULL; // new ChFrame<double>();
            ChFrame <double> abs_shaft2 = ChFrame <double> .FNULL; //new ChFrame<double>();

            ((ChFrame <double>)Body1).TransformLocalToParent(local_shaft1, abs_shaft1);
            ((ChFrame <double>)Body2).TransformLocalToParent(local_shaft2, abs_shaft2);

            ChVector vbdist = ChVector.Vsub(Get_shaft_pos1(), Get_shaft_pos2());
            // ChVector Trad1 = ChVector.Vnorm(ChVector.Vcross(Get_shaft_dir1(), ChVector.Vnorm(ChVector.Vcross(Get_shaft_dir1(), vbdist))));
            // ChVector Trad2 = ChVector.Vnorm(ChVector.Vcross(ChVector.Vnorm(ChVector.Vcross(Get_shaft_dir2(), vbdist)), Get_shaft_dir2()));

            double dist = ChVector.Vlength(vbdist);

            // compute actual rotation of the two wheels (relative to truss).
            ChVector md1 = abs_shaft1.GetA().MatrT_x_Vect(-vbdist);

            md1.z = 0;
            md1   = ChVector.Vnorm(md1);
            ChVector md2 = abs_shaft2.GetA().MatrT_x_Vect(-vbdist);

            md2.z = 0;
            md2   = ChVector.Vnorm(md2);

            double periodic_a1 = ChMaths.ChAtan2(md1.x, md1.y);
            double periodic_a2 = ChMaths.ChAtan2(md2.x, md2.y);
            double old_a1      = a1;
            double old_a2      = a2;
            double turns_a1    = Math.Floor(old_a1 / ChMaths.CH_C_2PI);
            double turns_a2    = Math.Floor(old_a2 / ChMaths.CH_C_2PI);
            double a1U         = turns_a1 * ChMaths.CH_C_2PI + periodic_a1 + ChMaths.CH_C_2PI;
            double a1M         = turns_a1 * ChMaths.CH_C_2PI + periodic_a1;
            double a1L         = turns_a1 * ChMaths.CH_C_2PI + periodic_a1 - ChMaths.CH_C_2PI;

            a1 = a1M;
            if (Math.Abs(a1U - old_a1) < Math.Abs(a1M - old_a1))
            {
                a1 = a1U;
            }
            if (Math.Abs(a1L - a1) < Math.Abs(a1M - a1))
            {
                a1 = a1L;
            }
            double a2U = turns_a2 * ChMaths.CH_C_2PI + periodic_a2 + ChMaths.CH_C_2PI;
            double a2M = turns_a2 * ChMaths.CH_C_2PI + periodic_a2;
            double a2L = turns_a2 * ChMaths.CH_C_2PI + periodic_a2 - ChMaths.CH_C_2PI;

            a2 = a2M;
            if (Math.Abs(a2U - old_a2) < Math.Abs(a2M - old_a2))
            {
                a2 = a2U;
            }
            if (Math.Abs(a2L - a2) < Math.Abs(a2M - a2))
            {
                a2 = a2L;
            }

            // compute new markers coordsystem alignment
            my = ChVector.Vnorm(vbdist);
            mz = Get_shaft_dir1();
            mx = ChVector.Vnorm(ChVector.Vcross(my, mz));
            mr = ChVector.Vnorm(ChVector.Vcross(mz, mx));
            mz = ChVector.Vnorm(ChVector.Vcross(mx, my));
            ChVector mz2, mx2, mr2, my2;

            my2 = my;
            mz2 = Get_shaft_dir2();
            mx2 = ChVector.Vnorm(ChVector.Vcross(my2, mz2));
            mr2 = ChVector.Vnorm(ChVector.Vcross(mz2, mx2));

            ma1.Set_A_axis(mx, my, mz);

            // rotate csys because of beta
            vrota.x = 0.0;
            vrota.y = beta;
            vrota.z = 0.0;
            mrotma.Set_A_Rxyz(vrota);
            marot_beta.nm.matrix.MatrMultiply(ma1.nm.matrix, mrotma.nm.matrix);
            // rotate csys because of alpha
            vrota.x = 0.0;
            vrota.y = 0.0;
            vrota.z = alpha;
            if (react_force.x < 0)
            {
                vrota.z = alpha;
            }
            else
            {
                vrota.z = -alpha;
            }
            mrotma.Set_A_Rxyz(vrota);
            ma1.nm.matrix.MatrMultiply(marot_beta.nm.matrix, mrotma.nm.matrix);

            ma2.nm.matrix.CopyFromMatrix(ma1.nm.matrix);

            // is a bevel gear?
            double be       = Math.Acos(ChVector.Vdot(Get_shaft_dir1(), Get_shaft_dir2()));
            bool   is_bevel = true;

            if (Math.Abs(ChVector.Vdot(Get_shaft_dir1(), Get_shaft_dir2())) > 0.96)
            {
                is_bevel = false;
            }

            // compute wheel radii so that:
            //            w2 = - tau * w1
            if (!is_bevel)
            {
                double pardist = ChVector.Vdot(mr, vbdist);
                double inv_tau = 1.0 / tau;
                if (!epicyclic)
                {
                    r2 = pardist - pardist / (inv_tau + 1.0);
                }
                else
                {
                    r2 = pardist - (tau * pardist) / (tau - 1.0);
                }
                r1 = r2 * tau;
            }
            else
            {
                double gamma2;
                if (!epicyclic)
                {
                    gamma2 = be / (tau + 1.0);
                }
                else
                {
                    gamma2 = be / (-tau + 1.0);
                }
                double al = ChMaths.CH_C_PI - Math.Acos(ChVector.Vdot(Get_shaft_dir2(), my));
                double te = ChMaths.CH_C_PI - al - be;
                double fd = Math.Sin(te) * (dist / Math.Sin(be));
                r2 = fd * Math.Tan(gamma2);
                r1 = r2 * tau;
            }

            // compute markers positions, supposing they
            // stay on the ideal wheel contact point
            mmark1     = ChVector.Vadd(Get_shaft_pos2(), ChVector.Vmul(mr2, r2));
            mmark2     = mmark1;
            contact_pt = mmark1;

            // correct marker 1 position if phasing is not correct
            if (checkphase)
            {
                double realtau = tau;
                if (epicyclic)
                {
                    realtau = -tau;
                }
                double m_delta;
                m_delta = -(a2 / realtau) - a1 - phase;

                if (m_delta > ChMaths.CH_C_PI)
                {
                    m_delta -= (ChMaths.CH_C_2PI);  // range -180..+180 is better than 0...360
                }
                if (m_delta > (ChMaths.CH_C_PI / 4.0))
                {
                    m_delta = (ChMaths.CH_C_PI / 4.0);  // phase correction only in +/- 45°
                }
                if (m_delta < -(ChMaths.CH_C_PI / 4.0))
                {
                    m_delta = -(ChMaths.CH_C_PI / 4.0);
                }

                vrota.x = vrota.y = 0.0;
                vrota.z = -m_delta;
                mrotma.Set_A_Rxyz(vrota);  // rotate about Z of shaft to correct
                mmark1 = abs_shaft1.GetA().MatrT_x_Vect(ChVector.Vsub(mmark1, Get_shaft_pos1()));
                mmark1 = mrotma.Matr_x_Vect(mmark1);
                mmark1 = ChVector.Vadd(abs_shaft1.GetA().Matr_x_Vect(mmark1), Get_shaft_pos1());
            }
            // Move Shaft 1 along its direction if not aligned to wheel
            double   offset = ChVector.Vdot(Get_shaft_dir1(), (contact_pt - Get_shaft_pos1()));
            ChVector moff   = Get_shaft_dir1() * offset;

            if (Math.Abs(offset) > 0.0001)
            {
                local_shaft1.SetPos(local_shaft1.GetPos() + Body1.TransformDirectionParentToLocal(moff));
            }

            // ! Require that the BDF routine of marker won't handle speed and acc.calculus of the moved marker 2!
            marker2.SetMotionType(ChMarker.eChMarkerMotion.M_MOTION_EXTERNAL);
            marker1.SetMotionType(ChMarker.eChMarkerMotion.M_MOTION_EXTERNAL);

            // move marker1 in proper positions
            newmarkpos.pos = mmark1;
            newmarkpos.rot = ma1.Get_A_quaternion();
            marker1.Impose_Abs_Coord(newmarkpos);  // move marker1 into teeth position
                                                   // move marker2 in proper positions
            newmarkpos.pos = mmark2;
            newmarkpos.rot = ma2.Get_A_quaternion();
            marker2.Impose_Abs_Coord(newmarkpos);  // move marker2 into teeth position

            // imposed relative positions/speeds
            deltaC.pos      = ChVector.VNULL;
            deltaC_dt.pos   = ChVector.VNULL;
            deltaC_dtdt.pos = ChVector.VNULL;

            deltaC.rot      = ChQuaternion.QUNIT; // no relative rotations imposed!
            deltaC_dt.rot   = ChQuaternion.QNULL;
            deltaC_dtdt.rot = ChQuaternion.QNULL;
        }
コード例 #30
0
ファイル: Carte.cs プロジェクト: crocovert/Musliw
        private void Carte_Paint(object sender, PaintEventArgs e)
        {
            int   i;
            float w, h;
            //projet = ((Musliw.MusliW)(this.MdiParent)).projet;
            Graphics page = e.Graphics;

            //page.Clear(this.BackColor);

            w = this.Width;
            h = this.Height;

            Pen  stylo = new Pen(fen.stylo_couleur, fen.epaisseur);
            Font fonte = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Bold);

            this.ForeColor = Color.Black;
            Brush brosse = new SolidBrush(fen.brosse_couleur);
            Brush brosse_texte = new SolidBrush(fen.couleur_texte);
            float dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
            float dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
            float deltax, deltay, voldeltax, voldeltay;
            float cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
            float cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);

            //MessageBox.Show(xl.ToString() + " " + yu.ToString());
            PointF p1 = new PointF();
            PointF p2 = new PointF();
            PointF p3 = new PointF();
            PointF p4 = new PointF();
            PointF p5 = new PointF();


            PointF[] points = new PointF[4];
            float    angle = 0, norme = 0;
            float    sinx = 0, cosx = 1;

            if (fen.volume_echelle < 1e-6f)
            {
                fen.volume_echelle = 1e-6f;
            }
            for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
            {
                norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
                {
                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                    deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                    deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                    cosx   = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
                    sinx   = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);

                    voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    page.DrawLine(stylo, ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay, ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax, ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay, ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);


                    p1.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay;
                    p1.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax;
                    p2.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay;
                    p2.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax;
                    p3.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay;
                    p3.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax;
                    p4.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay;
                    p4.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax;


                    System.Drawing.Drawing2D.GraphicsPath epaisseur       = new System.Drawing.Drawing2D.GraphicsPath();
                    System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    epaisseur.StartFigure();
                    points[0] = p1;
                    points[1] = p2;
                    points[2] = p3;
                    points[3] = p4;


                    epaisseur.AddPolygon(points);
                    epaisseur.CloseFigure();
                    //page.FillPath(brosse, epaisseur);
                    //page.FillPolygon(brosse, points);
                    //page.DrawPolygon(stylo,points);
                    epaisseur.Reset();
                    texte_epaisseur.StartFigure();
                    p5.X = 0.5f * (p3.X + p2.X);
                    p5.Y = 0.5f * (p3.Y + p2.Y);
                    texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
                    RectangleF encombrement = texte_epaisseur.GetBounds();
                    // texte_epaisseur.AddRectangle(encombrement);
                    //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);

                    page.FillPolygon(brosse, points);
                    page.DrawPolygon(stylo, points);

                    if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
                    {
                        System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();

                        if (cosx >= 0 && sinx <= 0)
                        {
                            angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(-0.5f * encombrement.Width * cosx, 0.5f * encombrement.Width * sinx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();
                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx >= 0)
                        {
                            angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx, -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx >= 0 && sinx >= 0)
                        {
                            angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI;
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(-0.5f * encombrement.Width * cosx, 0.5f * encombrement.Width * sinx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx <= 0)
                        {
                            angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx, -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                    }
                    epaisseur.Dispose();
                    texte_epaisseur.Dispose();
                }
            }

            /*        for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++)
             *  {
             *      if (projet.reseaux[nproj].nodes[i].i != 0)
             *      {
             *          //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
             *          //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
             *          page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
             *          page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
             *          page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f));
             *      }
             *  }*/
        }