Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »anti-freak« (25.12.2017, 22:12)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <georithm/rect.hpp> #include <georithm/circle.hpp> #include <georithm/contains.hpp> #include <georithm/vertices.hpp> #include <georithm/edges.hpp> int main() { georithm::Rect<int> rect(1, 1, 4, 4); // Rechteck an der Position (1/1) mit der Größe (4/4) georithm::Circle<int> circle(2, 2, 2); // Kreis mit der Center Position (2,2) und dem Radius 2 std::cout << "rect contains circle: " << georithm::contains(rect, circle) << std::endl; // prüft ob circle innerhalb von rect liegt (tut es übrigens nicht :P) std::cout << "rect contains center of circle: " << georithm::contains(rect, circle.getCenter()) << std::endl; // prüfen ob wenigstens der Center von circle in unserem rect liegt (das trifft zu) // das Ausgeben der Kanten Koordinaten std::cout << "Kanten gegen den Uhrzeigersinn:" << std::endl; for (auto edge : georithm::edges(rect)) { std::cout << "from x: " << edge.getPosition().getX() << " y: " << edge.getPosition().getY() << " to x: " << edge.getPosition().getX() + edge.getDirection().getX() << " y: " << edge.getPosition().getY() + edge.getDirection().getY() << std::endl; } // doch lieber anders rum auto edgesRange = georithm::edges(rect); std::cout << "\nKanten mit dem Uhrzeigersinn:" << std::endl; for (auto itr = edgesRange.crbegin(); itr != edgesRange.crend(); ++itr) { auto edge = *itr; std::cout << "from x: " << edge.getPosition().getX() << " y: " << edge.getPosition().getY() << " to x: " << edge.getPosition().getX() + edge.getDirection().getX() << " y: " << edge.getPosition().getY() + edge.getDirection().getY() << std::endl; } return 0; } |
Zitat
rect contains circle: 0
rect contains center of circle: 1
Kanten gegen den Uhrzeigersinn:
from x: 1 y: 1 to x: 1 y: 5
from x: 1 y: 5 to x: 5 y: 5
from x: 5 y: 5 to x: 5 y: 1
from x: 5 y: 1 to x: 1 y: 1
Kanten mit dem Uhrzeigersinn:
from x: 5 y: 1 to x: 1 y: 1
from x: 5 y: 5 to x: 5 y: 1
from x: 1 y: 5 to x: 5 y: 5
from x: 1 y: 1 to x: 1 y: 5
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »anti-freak« (27.12.2017, 15:37)
Administrator
Werbeanzeige