Пример #1
0
	/// Distance between point p and line segment p1, p2
	static double distance(math::vec3 const& p, math::vec3 const& p1, math::vec3 const& p2)
	{
		math::vec3 const v = p2 - p1;
		math::vec3 const w = p - p1;

		double const c1 = w.dot(v);
		double const c2 = v.dot(v);
		double const b = c1 / c2;

		math::vec3 const pb = p1 + v * b;
		return p.distance(pb);
	}
Пример #2
0
            void BoundingPolyhedron::positionAround(const math::vec3 desiredCentre, const std::vector<math::vec3>& points)
            {
                if(!mInitialised)
                    throw::std::runtime_error("Using uninitialised bounding polyhedron");

                if(points.size()==0)
                    return;

                auto bounding = calculateBoundSphere(points);

                float radius = (bounding.second + desiredCentre.distance(bounding.first))*mDesc.scaleMultiplier;
                setCentreAndRadius(desiredCentre, radius);
            }