3D-Linien-Segment und ebenenschnitt

Ich versuche zu realisieren eine Linie, segment und plane intersection-test, der true oder false zurück, je nachdem, ob oder nicht, es schneidet das Flugzeug. Auch wird es wieder den Kontakt Punkt auf der Ebene, wo die Linie schneidet, wenn die Linie nicht schneidet, ist die Funktion soll noch zurück, die Kreuzung war für mich der Punkt die Linie segmenent war ray. Ich benutzte die Informationen und den code von Christer Ericson Real-time Collision Detection, aber ich glaube nicht, dass im der Umsetzung ist es korrekt.

Dem Flugzeug im mit ist abgeleitet von dem normalen und vertice eines Dreiecks. Suche nach der Lage des Schnittpunktes auf der Ebene ist das, was ich will, unabhängig davon, ob oder nicht es liegt am Dreieck, die ich verwendet, um daraus das Flugzeug.

3D-Linien-Segment und ebenenschnitt

Die Parameter der Funktion sind wie folgt:

contact = the contact point on the plane, this is what i want calculated
ray = B - A, simply the line from A to B
rayOrigin = A, the origin of the line segement
normal = normal of the plane (normal of a triangle)
coord = a point on the plane (vertice of a triangle)

Hier ist der code im Einsatz:

bool linePlaneIntersection(Vector& contact, Vector ray, Vector rayOrigin, Vector normal, Vector coord) {

    //calculate plane
    float d = Dot(normal, coord);

    if (Dot(normal, ray)) {
        return false; //avoid divide by zero
    }

    //Compute the t value for the directed line ray intersecting the plane
    float t = (d - Dot(normal, rayOrigin)) / Dot(normal, ray);

    //scale the ray by t
    Vector newRay = ray * t;

    //calc contact point
    contact = rayOrigin + newRay;

    if (t >= 0.0f && t <= 1.0f) {
        return true; //line intersects plane
    }
    return false; //line does not
}

In meinen tests, es nie wieder wahr... irgendwelche Ideen?

ist diese im 2D oder 3D ??
dieser test ist in 3D
haben Sie sich entschlossen, in das Ende?

InformationsquelleAutor kbirk | 2011-08-23

Schreibe einen Kommentar