@@ -170,14 +170,30 @@ std::array<ticl::Vector, 3> TracksterLinkingbySkeletons::findSkeletonNodes(
170170bool isInCylinder (const std::array<ticl::Vector, 3 > &mySkeleton,
171171 const std::array<ticl::Vector, 3 > &otherSkeleton,
172172 const float radius_sqr) {
173- const auto ¢er = mySkeleton[1 ];
173+ const auto &first = mySkeleton[0 ];
174+ const auto &last = mySkeleton[2 ];
174175 const auto &pointToCheck = otherSkeleton[0 ];
175- const auto distance2_xy = (pointToCheck.x () - center.x ()) * (pointToCheck.x () - center.x ()) +
176- (pointToCheck.y () - center.y ()) * (pointToCheck.y () - center.y ());
177- LogDebug (" TracksterLinkingbySkeletons" ) << " Distance XY " << distance2_xy << std::endl;
178- bool isWithinZ = std::abs (pointToCheck.z ()) >= std::abs (mySkeleton[0 ].z ()) and
179- std::abs (pointToCheck.z ()) <= std::abs (mySkeleton[2 ].z ());
180- return (distance2_xy <= radius_sqr) && isWithinZ;
176+
177+ const auto &cylAxis = last - first;
178+ const auto &vecToPoint = pointToCheck - first;
179+
180+ auto axisNorm = cylAxis.Dot (cylAxis);
181+ auto projLength = vecToPoint.Dot (cylAxis) / axisNorm;
182+ bool isWithinLength = projLength >= 0 && projLength <= 1 ;
183+
184+ if (!isWithinLength)
185+ return false ;
186+
187+ const auto &proj = cylAxis * projLength;
188+
189+ const auto &pointOnAxis = first + proj;
190+
191+ const auto &distance = pointToCheck - pointOnAxis;
192+ auto distance2 = distance.Dot (distance);
193+
194+ bool isWithinRadius = distance2 <= radius_sqr;
195+
196+ return isWithinRadius;
181197}
182198
183199bool TracksterLinkingbySkeletons::areCompatible (const ticl::Trackster &myTrackster,
0 commit comments