Skip to content

Commit

Permalink
Hangprinter: Generalize IsReachable() to any pyramid
Browse files Browse the repository at this point in the history
This is a clean generalization from 4 to N.
Better documented and cleaner thanks to @tobbelobb on github.
  • Loading branch information
jtimon committed Feb 22, 2023
1 parent 7b65487 commit 0e208a8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Movement/Kinematics/HangprinterKinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,23 @@ static bool isSameSide(float const v0[3], float const v1[3], float const v2[3],
return dot0*dot1 > 0.0F;
}

static bool isInsideTetrahedron(float const point[3], float const tetrahedron[4][3]){
return isSameSide(tetrahedron[0], tetrahedron[1], tetrahedron[2], tetrahedron[3], point) &&
isSameSide(tetrahedron[2], tetrahedron[1], tetrahedron[3], tetrahedron[0], point) &&
isSameSide(tetrahedron[2], tetrahedron[3], tetrahedron[0], tetrahedron[1], point) &&
isSameSide(tetrahedron[0], tetrahedron[3], tetrahedron[1], tetrahedron[2], point);
}

// For each triangle side in a pyramid, check if the point is inside the pyramid. Plus check the base too
// Precondition: all the base anchors belong to the same plane,
// except the top (last) anchor which is above that plane with respect to the bed
bool HangprinterKinematics::IsReachable(float axesCoords[MaxAxes], AxesBitmap axes) const noexcept /*override*/
{
float const coords[3] = {axesCoords[X_AXIS], axesCoords[Y_AXIS], axesCoords[Z_AXIS]};
return isInsideTetrahedron(coords, anchors);
bool reachable = true;

// First we check is above the base plane
reachable = isSameSide(anchors[0], anchors[1], anchors[2], anchors[HANGPRINTER_AXES - 1], coords);

// Check all the planes defined by triangle sides in the pyramid
for (size_t i = 0; reachable && i < HANGPRINTER_AXES - 1; ++i) {
reachable = isSameSide(anchors[i], anchors[(i+1) % (HANGPRINTER_AXES - 1)], anchors[HANGPRINTER_AXES - 1], anchors[(i+2) % (HANGPRINTER_AXES - 1)], coords);
}

return reachable;
}

// Limit the Cartesian position that the user wants to move to returning true if we adjusted the position
Expand Down

0 comments on commit 0e208a8

Please sign in to comment.