コード例 #1
0
    /// <summary>
    ///     Trouver le point d'intersection entre deux droites.
    ///	</summary>
    /// <param name='fonctionA'>
    ///		L'un des deux fonctions
    ///	</param>
    /// <param name='fonctionB'>
    ///		L'un des deux fonctions
    ///	</param>
    /// <param name='intersection'>
    ///		Le point d'intersection entre les deux droites. S'il n'y a pas de point d'intersection, la valeur est Vector.zero.
    ///	</param>
    /// <returns>
    ///		True s'il y a un point d'intersection. False, sinon.
    /// </returns>
    public static bool Intersect(FonctionAffine fonctionA, FonctionAffine fonctionB, out Vector3 intersection)
    {
        bool areIntersecting = false;

        intersection = Vector3.zero;

        //Vérifier si les pentes sont parallèles
        if (fonctionA.pente != fonctionB.pente)
        {
            //Trouver l'intersection
            intersection.x = (fonctionB.ordonne - fonctionA.ordonne) / (fonctionA.pente - fonctionB.pente);
            intersection.z = (fonctionA.pente * intersection.x) + fonctionA.ordonne;

            areIntersecting = true;
        }
        else
        {
            //Les pentes doivent se superposent pour que les fonctions s'intersectionne
            if (fonctionA.ordonne == fonctionB.ordonne)
            {
                //Assigner l'ordonnée à l'orginne comme intersection
                intersection.x = 0;
                intersection.z = fonctionA.ordonne;

                areIntersecting = true;
            }
        }

        return(areIntersecting);
    }
コード例 #2
0
    /// <summary>
    ///     Calculer la position d'un waypoint à partir du point de fin du vecteur.
    /// </summary>
    /// <param name='distance'>
    ///     La distance entre le waypoint et le point de fin.
    ///	</param>
    /// <returns>
    ///     Le waypoint.
    ///	</returns>
    public Vector3 getWaypointFromEnd(float distance)
    {
        Vector3 waypoint = endPoint;

        if (startPoint.x == endPoint.x)
        {
            if (startPoint.z < endPoint.z)
            {
                waypoint.z += distance;
            }
            else
            {
                waypoint.z -= distance;
            }
        }
        else
        {
            FonctionAffine fonction = new FonctionAffine(startPoint, endPoint);
            float          ecart    = Mathf.Sqrt(Mathf.Pow(distance, 2) / (1 + Mathf.Pow(fonction.pente, 2)));

            if (startPoint.x < endPoint.x)
            {
                waypoint.x += ecart;
                waypoint.z  = fonction.getImage(waypoint.x);
            }
            else
            {
                waypoint.x -= ecart;
                waypoint.z  = fonction.getImage(waypoint.x);
            }
        }

        return(waypoint);
    }