bsp.cpp 1.4 KB

123456789101112131415161718192021222324252627282930
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* bsp.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/07/18 19:15:01 by Bastien Cha #+# #+# */
  9. /* Updated: 2025/12/18 13:11:51 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Point.class.hpp"
  13. #include <iostream>
  14. Fixed orient(Point const & a, Point const & b, Point const & p) {
  15. return (b.getX() - a.getX()) * (p.getY() - a.getY()) - (b.getY() - a.getY()) * (p.getX() - a.getX());
  16. }
  17. bool bsp(Point const & a, Point const & b, Point const & c, Point const & point) {
  18. Fixed o1, o2, o3;
  19. o1 = orient(a, b, point);
  20. o2 = orient(b, c, point);
  21. o3 = orient(c, a, point);
  22. if ((o1 > 0 && o2 > 0 && o3 > 0) || (o1 < 0 && o2 < 0 && o3 < 0))
  23. return true;
  24. return false;
  25. }