Line<T, Dim>::Line(const Hyperplane<T, 2>& plane) { static_assert(Dim == 2, "Line dimension must be two, since it a plane in 2 dimensional space."); // Intersect plane's line with line through origo perpendicular to plane to find suitable base T a = plane.Normal()(0); T b = plane.Normal()(1); T d = plane.Scalar(); T div = (a*a + b*b); base = { a*d / div, b*d / div }; direction = { b, -a }; }
Vector3d getPlaneIntersection( const Hyperplane<double,3> &plane1, const Hyperplane<double,3> &plane2, double lambda) { double dot = plane1.normal().dot(plane2.normal()); Vector3d cross = plane1.normal().cross(plane2.normal()); double c1 = (plane1.offset() - plane2.offset()*dot )/(1.0-dot*dot); double c2 = (plane2.offset() - plane1.offset()*dot )/(1.0-dot*dot); Vector3d r = (c1*plane1.normal() + c2*plane2.normal() ) + lambda*(cross); return r; }
bool OjaData::derivative(const Point& x,const Point& direction,double& Dpos ,double& Dneg) const { Point d=direction; d.normalize(); Index I(dim(),size()); Hyperplane H; double D; // Apumuuttuja yhden termi laskemiseen double sum=0.0; // Summa positiiviseen suuntaan double sum_=0.0; // Summa negatiiviseen suuntaan double k=1.0 / double(fact(dim())); double sgn; for(int i=0; i<hyperplanes(); i++) { if(planes) H=hyperplane(i); else { H.get(*this,I); I++; } H.normalize(); D = k * (H|d); sgn = H.side(x); if(sgn > 0) // Piste ei ole hypertasolla sum += D, sum_ -= D; else if (sgn < 0) sum -= D, sum_ += D; else // Piste on hypertasolla sum += fabs(D), sum_ += fabs(D); } Dpos = sum; Dneg = sum_; return Dpos >= 0.0 && Dneg >= 0.0; }
Vector3d getReflected(const Vector3d &p, const Hyperplane<double,3> &plane) { Vector3d r = p- 2*plane.signedDistance(p)*plane.normal(); return r; }