CPP02 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
bsp.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* bsp.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/04/28 17:18:33 by kamitsui #+# #+# */
9/* Updated: 2025/05/06 17:58:04 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
21#include "Fixed.hpp"
22#include "Point.hpp"
23#include <iostream>
24
35Fixed crossProduct(const Point &a, const Point &b, const Point &c) {
36 return (b.getX() - a.getX()) * (c.getY() - a.getY()) - (b.getY() - a.getY()) * (c.getX() - a.getX());
37}
38
51bool bsp(Point const a, Point const b, Point const c, Point const point) {
52 Fixed cp1 = crossProduct(a, b, point);
53 Fixed cp2 = crossProduct(b, c, point);
54 Fixed cp3 = crossProduct(c, a, point);
55
56 bool allPositive = (cp1 > Fixed(0) && cp2 > Fixed(0) && cp3 > Fixed(0));
57 bool allNegative = (cp1 < Fixed(0) && cp2 < Fixed(0) && cp3 < Fixed(0));
58
59 return allPositive || allNegative;
60}
Header file for the Point class representing a 2D point with Fixed coordinates.
bool bsp(Point const a, Point const b, Point const c, Point const point)
Determines if a point is strictly inside a triangle defined by three other points.
Definition bsp.cpp:51
Fixed crossProduct(const Point &a, const Point &b, const Point &c)
Helper function to calculate the 2D cross product of vectors (b-a) and (c-a).
Definition bsp.cpp:35
ex00 Fixed Class
Definition Fixed.hpp:28
Fixed getY() const
Gets the y-coordinate of the point.
Definition Point.cpp:81
Fixed getX() const
Gets the x-coordinate of the point.
Definition Point.cpp:74
Header file for the Fixed class representing fixed-point numbers with overloaded operators and min/ma...