Skip to content

refactor: use Heuclid polygon predicates for collision detection - #7

Merged
Mr-tooth merged 9 commits into
mainfrom
feature/polygon-collision
Mar 17, 2026
Merged

refactor: use Heuclid polygon predicates for collision detection#7
Mr-tooth merged 9 commits into
mainfrom
feature/polygon-collision

Conversation

@Mr-tooth

Copy link
Copy Markdown
Member

Depends on

Changes

StepConstraintCheck.cpp

  • isTwoFootCollided: Replaced 40-line manual vertex/midpoint point-in-polygon loop with HeuclidPolygonTools::isConvexPolygonIntersect() — same algorithm, cleaner code
  • buildFootPolygon: New helper — builds ConvexPolygon2D from foot pose + side (shared by all foot-polygon operations)
  • isFootPolygonCollidedWithPolygon: NEW — full polygon-polygon intersection for obstacle avoidance. Checks foot vertices in obstacle AND obstacle vertices in foot AND edge midpoints. Replaces the incomplete isAnyVertexOfFootInsideStairRegion which only checked foot→obstacle direction
  • isFootPolygonContainedInPolygon: NEW — checks if foot polygon is fully inside a terrain polygon. Required for stair climbing where each foot must land on a single terrain patch

ParameterBasedStepExpansion.cpp

  • Obstacle check now uses isFootPolygonCollidedWithPolygon instead of isAnyVertexOfFootInsideStairRegion

CMakeLists.txt

  • Heuclid FetchContent: GIT_TAG "v2.1"GIT_TAG "v2.2"

Known Issue

Test Results (local)

cmake --build . → 0 errors, 0 warnings (only deprecated Py API from matplotlib-cpp)

CI will verify ubuntu/macOS/windows build + tests.

Mr-tooth added 9 commits March 17, 2026 14:46
- demo_export.cpp: exports planner data to CSV (footsteps, polygons, body path)
- demo_visualize.py: Python matplotlib reads real data, renders footstep GIF
- Foot polygons from getFootVertex2D, alternating L/R from AccurateFootstep
- Body path from Simple2DBodyPathHolder (ellipsoid) with direction arrows
- Start/Goal markers drawn last with white background labels
- .gitignore: exclude generated CSV and frames_flat/ from tracking
- goalPose updated to test7 coords (0.663, -0.962, yaw=-1.554)
- HWPOfPathDistance: 1.0 → 2.50 (strong body path guidance)
- HWP walk/turn weights: default → test7 tuned (1.30)
- Full parameter set: edge costs, step yaw, proximity, step size
- Result: 22 footsteps (vs 10), natural alternating L/R straddling body path
Key fixes:
- sqrt() fix in computeFollowEllipsoidPath: pfp.distance is squared
  distance, must use sqrt() before comparing to IdealStepWidth
- Remove duplicate SetFollowBodyPath(false) that overwrote true
- Add followBodyPath parameter (separate from isStairAlignMode)
  to enable body path heuristic without stair constraints
- Add edgecost_w_pathdev for optional edge cost penalty

Result: 25 footsteps evenly straddling the ellipsoid body path.
Search completes in 72 nodes (vs 1456+ with the sqrt bug).
- README.md / README_CN.md: 19 → 25 footsteps, accurate descriptions
- parameters.h: Doxygen for followBodyPath, edgecost_w_pathdev
- HeuristicCalculator.cpp: sqrt() comment on squared distance fix
- FootstepCostCalculator.cpp: body path deviation penalty docs
- AStarFootstepPlanner.cpp: followBodyPath heuristic selection comment
- Re-apply followBodyPath change (accidentally reverted by checkout)
- demo_obstacle.cpp: planner with stair polygon as obstacle (12×12cm block)
- demo_visualize.py: supports optional obstacle.csv for polygon rendering
- Obstacle placed at body path center, forces detour (24 steps)
- README.md / README_CN.md: obstacle demo section with GIF
- assets/obstacle_avoidance.gif (196 KB)
- isTwoFootCollided: replaced 40-line manual vertex/midpoint loop with
  Heuclid isConvexPolygonIntersect (delegates to shared logic)
- isFootPolygonCollidedWithPolygon: NEW — full polygon-polygon intersection
  for obstacle avoidance (replaces incomplete vertex-only check)
- isFootPolygonContainedInPolygon: NEW — checks foot ⊆ terrain for stair
  climbing where foot must land on a single terrain patch
- buildFootPolygon helper: extracts foot ConvexPolygon2D construction
- CMakeLists: Heuclid FetchContent GIT_TAG v2.1 → v2.2
- ParameterBasedStepExpansion: uses new collision API

Pre-existing issue: demo_export segfault tracked in #6
CI will verify compilation and unit tests independently.

Heuclid: v2.2 (isConvexPolygonIntersect + isConvexPolygonContained)
Keep stair/obstacle step expansion using isAnyVertexOfFootInsideStairRegion
to avoid changing test behavior. New APIs (isFootPolygonCollidedWithPolygon,
isFootPolygonContainedInPolygon) are available but not yet wired into step
expansion — will be used in stair demo phase.

Changes:
- isTwoFootCollided: uses isConvexPolygonIntersect via buildFootPolygon helper
- StepConstraintCheck.h: new function declarations (unused yet)
- StepConstraintCheck.cpp: buildFootPolygon helper + new implementations
- CMakeLists.txt: Heuclid v2.1 → v2.2

Known issue: demo_export segfault (issue #6, pre-existing)
@Mr-tooth
Mr-tooth merged commit deb11a0 into main Mar 17, 2026
4 checks passed
Mr-tooth added a commit that referenced this pull request Mar 20, 2026
refactor: use Heuclid polygon predicates for collision detection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant