Willkommen ~Gast!
Registrieren || Einloggen || Hilfe/FAQ || Staff
Probleme mit der Registrierung im Forum? Melde dich unter registerEin Bild.
Autor Beitrag
025
20.07.2004, 13:47
semmelrogge



falls du etwas pascal kannst ... nimm einfach diese beiden funktionen !

hierbei ist es egal ob die konkav sind oder sonstwie aussehen !
die eckpunkte des einen polygons übergibst du als dynamischen array +eckpunkt count! -> math3dInsidePolygon!

aus dem anderen polygon holst du die einzelen eckpunkte (als 3d vectoren)einzeln nacheinander heraus und übergibst sie an die selbe funktion math3dInsidePolygon (vIntersection) ... (EINZELN)
nun springst du die funktion je eckpunkt einmal an ... beim ersten mal , wenn das ding ein true zurückgibt, hast du ne kollision ! - gibt das ding nur "false" zurück (für jeden eckpunkt), gibts natürlich keine :)

ps:Td3DXVector3 -> das ding ist ein type (3 floats für die 3d pos)

function math3dAngleBetweenVectors(Vector1, Vector2:TD3DXVector3):double;
var vectorsMagnitude,
dotProduct : float;
begin // Get the dot product of the vectors
dotProduct := math3dDot(Vector1, Vector2);
// Get the product of both of the vectors magnitudes
vectorsMagnitude := math3dMagnitude(Vector1) * math3dMagnitude(Vector2) ;
// Get the angle in radians between the 2 vectors
result := arccos( dotProduct / vectorsMagnitude );
// Here we make sure that the angle is not a -1.#IND0000000 number, which means indefinate
if IsNAN(result) then result:=0;
end;

function math3dInsidePolygon(vIntersection:TD3DXVector3;Poly:Array of TD3DXVector3;verticeCount:longint):boolean;
const MATCH_FACTOR:double = 0.99; // Used to cover up the error in floating point
var Angle : double;
vA, vB : Td3DXVector3; // temporäre vectoren
i : integer;
begin // Initialize the angle
Angle := 0;
// Go in a circle to each vertex and get the angle between
for i:=0 to verticeCount-1 do
begin // Subtract the intersection point from the current vertex
vA := math3dSub(Poly[i],vIntersection);
vB := math3dSub(Poly[(i + 1) mod verticeCount],vIntersection);
// Find the angle between the 2 vectors and add them all up as we go along
Angle:=Angle+math3dAngleBetweenVectors(vA, vB);
end;
// If the angle is greater than 2 PI, (360 degrees)
if Angle>=MATCH_FACTOR * (2 * PI) then
begin result:=true; // punkt ist im polygon
exit;
end;
// nicht drinne
result:=false;
end;

--

zum Seitenanfang zum Seitenende Profil || Suche
026
22.07.2004, 22:27
Prefect



Wenn ich mich recht erinnere ging es darum, zwei Polygone in 2D auf Überschneidung zu prüfen. Dein (dank fehlender Formatierung unübersichtler - siehe [ code ]) Code vergleicht dagegen einen Punkt mit einem Polygon.

cu,
Prefect

--

Widelands - Gemütliche Aufbaustrategie, Free Software
Noch ein Blog - Lerne, wie die Welt wirklich ist, aber vergiss niemals, wie sie sein sollte.

zum Seitenanfang zum Seitenende Profil || Suche