[Maths] un sytème de 3 eq à 3 inconnues

un sytème de 3 eq à 3 inconnues [Maths] - Programmation

Marsh Posté le 13-03-2002 à 10:48:24    

Bon, pour faire de la détection de collision, je dois savoir si une ligne rencontre une face...
 
POur cela, j'ai pensé trouver où la ligne traverse le plan de la face, et ensuite regarder si ce point est dans la face ou dehors...
 
pour ça, il faut que je résolve un système de 3 équations à 3 inconnues... (3*(ax+by+cz+d=0) , x,y,z étant les inconnues)
(je peux rajouter une 4ème équation au besoin)
 
Bon ça je sais faire... Mais je voudrais tester avant si le système admet des solutions, je me rappelle qu'il y a un truc avec les déterminants, mais je ne me souviens plus exactement...
 
Quelqu'un pourrait il m'éclairer ?

Reply

Marsh Posté le 13-03-2002 à 10:48:24   

Reply

Marsh Posté le 13-03-2002 à 10:53:30    

tu te compliques la vie.
 
http://www.faqs.org/faqs/graphics/algorithms-faq/
 
Subject 5.06: How do I determine the intersection between a ray and a triangle?
 
    First find the intersection between the ray and the plane in which
    the triangle is situated. Then see if the point of intersection is
    inside the triangle.
    Details may be found in [O'Rourke (C)] pp.226-238, whose code is at
       http://cs.smith.edu/~orourke/ .
    Efficient code complete with statistical tests is described in the Mo:ller-
    Trumbore paper in J. Graphics Tools (C code downloadable from there):
       http://www.acm.org/jgt/papers/MollerTrumbore97/
    See also the full paper:
       http://www.Graphics.Cornell.EDU/pubs/1997/MT97.html
    See also the "3D Object Intersection" page, described in Subject 0.05.
 
ou dans l'exemple 'pick' de directx :  
 
//-----------------------------------------------------------------------------
// Name: IntersectTriangle()
// Desc: Given a ray origin (orig) and direction (dir), and three vertices of
//       of a triangle, this function returns TRUE and the interpolated texture
//       coordinates if the ray intersects the triangle
//-----------------------------------------------------------------------------
BOOL CMyD3DApplication::IntersectTriangle( const D3DXVECTOR3& orig,
                                       const D3DXVECTOR3& dir, D3DXVECTOR3& v0,
                                       D3DXVECTOR3& v1, D3DXVECTOR3& v2,
                                       FLOAT* t, FLOAT* u, FLOAT* v )
{
    // Find vectors for two edges sharing vert0
    D3DXVECTOR3 edge1 = v1 - v0;
    D3DXVECTOR3 edge2 = v2 - v0;
 
    // Begin calculating determinant - also used to calculate U parameter
    D3DXVECTOR3 pvec;
    D3DXVec3Cross( &pvec, &dir, &edge2 );
 
    // If determinant is near zero, ray lies in plane of triangle
    FLOAT det = D3DXVec3Dot( &edge1, &pvec );
 
    D3DXVECTOR3 tvec;
    if( det > 0 )
    {
        tvec = orig - v0;
    }
    else
    {
        tvec = v0 - orig;
        det = -det;
    }
 
    if( det < 0.0001f )
        return FALSE;
 
    // Calculate U parameter and test bounds
    *u = D3DXVec3Dot( &tvec, &pvec );
    if( *u < 0.0f || *u > det )
        return FALSE;
 
    // Prepare to test V parameter
    D3DXVECTOR3 qvec;
    D3DXVec3Cross( &qvec, &tvec, &edge1 );
 
    // Calculate V parameter and test bounds
    *v = D3DXVec3Dot( &dir, &qvec );
    if( *v < 0.0f || *u + *v > det )
        return FALSE;
 
    // Calculate t, scale parameters, ray intersects triangle
    *t = D3DXVec3Dot( &edge2, &qvec );
    FLOAT fInvDet = 1.0f / det;
    *t *= fInvDet;
    *u *= fInvDet;
    *v *= fInvDet;
 
    return TRUE;
}

Reply

Marsh Posté le 14-03-2002 à 15:01:04    

Merci beaucoup...
Désolé, mais j'ai pas pu poster avant... FT m'a niqué ma ligne : sympa !!! enfin bon je la récupère demain après midi...

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed