mathc
mathc copied to clipboard
Geometry
I think it would be useful to have functions to detect intersection between primitives:
For 2D:
- [x] Point × Circle
- [x] Point × Triangle
- [ ] Circle × Circle
- [ ] Circle × Triangle
- [ ] Triangle × Triangle
For 3D:
- [ ] Line segment × Triangle
- [ ] Triangle × Triangle
Then, more complex shapes would be only a combination of those. For example, intersection between rectangles would be checking 4 triangles.
Preliminary design for the functions:
bool circle_circle_intersect(struct vec circle_position1, float radius1,
struct vec circle_position1, float radius1,
struct contact *result);
bool circle_triangle_intersect(struct vec circle_position, float radius,
struct vec a, struct vec b, struct vec c,
struct contact *result);
bool triangle_triangle_intersect(struct vec a1, struct vec b1, struct vec c1,
struct vec a2, struct vec b2, struct vec c2,
struct contact *result);
I don't think it would be worth to add a new structure (for example, struct triangle
) just for this case. But, a contact
structure is probably necessary, since two primitives can have multiple contact points (multiple vectors):
struct contact {
uint32_t count;
struct vec v[6];
};
AABB overlap would be handy, it's much simpler than general case box overlap and is a common operation.