@@ -344,17 +344,27 @@ static bool isSameSide(float const v0[3], float const v1[3], float const v2[3],
344344 return dot0*dot1 > 0 .0F ;
345345}
346346
347- static bool isInsideTetrahedron (float const point[3 ], float const tetrahedron[4 ][3 ]){
348- return isSameSide (tetrahedron[0 ], tetrahedron[1 ], tetrahedron[2 ], tetrahedron[3 ], point) &&
349- isSameSide (tetrahedron[2 ], tetrahedron[1 ], tetrahedron[3 ], tetrahedron[0 ], point) &&
350- isSameSide (tetrahedron[2 ], tetrahedron[3 ], tetrahedron[0 ], tetrahedron[1 ], point) &&
351- isSameSide (tetrahedron[0 ], tetrahedron[3 ], tetrahedron[1 ], tetrahedron[2 ], point);
352- }
353-
347+ // For each triangle side in a pyramid, check if the point is inside the pyramid. Plus check the base too.
354348bool HangprinterKinematics::IsReachable (float axesCoords[MaxAxes], AxesBitmap axes) const noexcept /* override*/
355349{
356350 float const coords[3 ] = {axesCoords[X_AXIS ], axesCoords[Y_AXIS ], axesCoords[Z_AXIS ]};
357- return isInsideTetrahedron (coords, anchors);
351+
352+ bool reachable = isSameSide (anchors[0 ], anchors[1 ], anchors[2 ], anchors[HANGPRINTER_AXES - 1 ], coords);
353+
354+ for (size_t i = 1 ; reachable && i < HANGPRINTER_AXES - 3 ; ++i)
355+ {
356+ reachable = isSameSide (anchors[i], anchors[i + 1 ], anchors[HANGPRINTER_AXES - 1 ], anchors[i + 2 ], coords);
357+ }
358+ if (reachable)
359+ {
360+ reachable = isSameSide (anchors[HANGPRINTER_AXES - 3 ], anchors[HANGPRINTER_AXES - 2 ], anchors[HANGPRINTER_AXES - 1 ], anchors[0 ], coords);
361+ }
362+ if (reachable)
363+ {
364+ reachable = isSameSide (anchors[HANGPRINTER_AXES - 2 ], anchors[0 ], anchors[HANGPRINTER_AXES - 1 ], anchors[1 ], coords);
365+ }
366+
367+ return reachable;
358368}
359369
360370// Limit the Cartesian position that the user wants to move to returning true if we adjusted the position
0 commit comments