summaryrefslogtreecommitdiff
path: root/thirdparty/thekla_atlas/nvmath/Plane.cpp
blob: 8b54f829adda00fdc5f450bea4287d4cf21bd470 (plain)
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
// This code is in the public domain -- castanyo@yahoo.es

#include "Plane.h"
#include "Plane.inl"
#include "Matrix.inl"

namespace nv
{
    Plane transformPlane(const Matrix & m, const Plane & p)
    {
        Vector3 newVec = transformVector(m, p.vector());

        Vector3 ptInPlane = p.offset() * p.vector();
        ptInPlane = transformPoint(m, ptInPlane);

        return Plane(newVec, ptInPlane);
    }

    Vector3 planeIntersection(const Plane & a, const Plane & b, const Plane & c)
    {
        return dot(a.vector(), cross(b.vector(), c.vector())) * (
            a.offset() * cross(b.vector(), c.vector()) + 
            c.offset() * cross(a.vector(), b.vector()) +
            b.offset() * cross(c.vector(), a.vector()));
    }

} // nv namespace