Plane.c 613 B

1234567891011121314151617181920
  1. #include "core/Plane.h"
  2. #include "core/Generic.h"
  3. #include "core/ToString.h"
  4. void initPlane(Plane* p, const Vector3* a, const Vector3* b, const Vector3* c) {
  5. cross(&p->abc, sub(b, a), sub(c, a));
  6. normalize(&p->abc);
  7. p->d = -dot(&p->abc, b);
  8. }
  9. float signedDistance(const Plane* p, const Vector3* v) {
  10. return dot(&p->abc, v) + p->d;
  11. }
  12. size_t toStringPlane(const Plane* p, char* buffer, size_t n) {
  13. return toString(buffer, n, "(%.3f x + %.3f y + %.3f z + %.3f)",
  14. (double)p->abc.data[0], (double)p->abc.data[1],
  15. (double)p->abc.data[2], (double)p->d);
  16. }