bool Utils::CalcTangent( const Vec2d& p1, const Vec2d& p2, const Vec2d& p3, Vec2d& tangent ) { Vec2d mid1 = (p1 + p2) * 0.5; Vec2d norm1 = VecNorm(p2 - p1); Vec2d mid2 = (p2 + p3) * 0.5; Vec2d norm2 = VecNorm(p3 - p2); double t; if( !LineCrossesLine(mid1, norm1, mid2, norm2, t) ) { if( p1 != p3 ) { tangent = VecUnit(p3 - p1); return true; } return false; } Vec2d centre = mid1 + norm1 * t; // tangent = p2 - centre; // tangent = VecNorm(p2 - centre); tangent = VecUnit(VecNorm(p2 - centre)); if( norm1 * (p3 - p1) < 0 ) tangent = -tangent; return true; }
//==========================================================================* // Utility to find crossing point (Schnittpunkt zweier Geraden) //--------------------------------------------------------------------------* bool TUtils::LineCrossesLineXY( const TVec3d& p0, const TVec3d& v0, const TVec3d& p1, const TVec3d& v1, double& t ) { return LineCrossesLine(p0.x, p0.y, v0.x, v0.y, p1.x, p1.y, v1.x, v1.y, t); }
double Utils::CalcCurvatureTan( const Vec2d& p1, const Vec2d& tangent, const Vec2d& p2 ) { Vec2d v = VecUnit(VecNorm(tangent)); Vec2d u = VecNorm(p2 - p1); Vec2d q = (p1 + p2) * 0.5; double radius; if( !LineCrossesLine(p1, v, q, u, radius) ) return 0; else return 1.0 / radius; }
bool Utils::LineCrossesLine( const Vec2d& p0, const Vec2d& v0, const Vec2d& p1, const Vec2d& v1, double& t ) { return LineCrossesLine(p0.x, p0.y, v0.x, v0.y, p1.x, p1.y, v1.x, v1.y, t); }