Git Product home page Git Product logo

Comments (1)

Glidias avatar Glidias commented on June 6, 2024 1

Here's my possible approach:

Begin with a BFS search starting from current cell position at current point towards potentially up to 26 neighbours (for 2D case with cellsY === 1), up to 8 neighbours only). Consider doing this up to a maximum depth setting before "giving" up and going along with worse case scenerio (note, this unlikely to be case, and for such cases, usually a more globalised an octree strcuture that leads down to individual localised CellSPacePartionings, would be done to avoid such a worse case situation by narrowing down to neighboring occupied spaces from current position. This is typically done for highly convex navmesh worlds lot of empty spaces where a single monolithic CellSpacePartioning structure wouldn't be too ideal. (A generalised utility that actually handles such common grid-based searches on generalised 2D/3D with function callback, could come in handy)

The general idea is to start with the current celll and hope to find a closest distance candidate result (best case scenerio). With that result, the subsequech s searches along neighboring cells will be bounded and eventually the overall search space is kept small.

Pseudo code:

curMinRequiredDist = minRequiredDistParam != null ? minRequiredDistParam : Infinity;
currentClosestPolygon = null

foreach cell in BFS, starting from root currentCellAtPosition {
   if (cell === currentCellAtPosition || distToCellFrom(currentPos) < curMinRequiredDist) {
   for all (not yet visited) polygons in cell:
    dist = getDistToPolygonForCurrentCycle(poly)
    if (dist < curMinRequiredDist) {
       dist = curMinRequiredDist;
       currentClosestPolygon = polygon;
    }
  }
}

Offhand, i think the generalised closest 3D distance to polygon can start out by checking on whether the point lies within polygon's plane projected bounds. (basically the point has to lie within all edge planes extruded out along the plane normal of the polygon, which you can get with the cross product between each edge delta (<- normalised edge.direction() not needed) and plane normal vector). Note that normalisation of this cross product product result isn't need for this case either since you are measuring inside/outside case only. If point lies positively "within" all of the projected polygon bounds (dot product of point vs edge crossed direction), use the distance to polygon's plane. Else , get distance to closest line segment of polygon's edge. (can also early-out skip "back-facing" edges normals in relation to the point as well as those points definitely lie further away), so not all line segments needs to be tested. So, the closest point is than clamped to either the plane or edge of the polygon, depending on whether the point is inside or outside the projected plane normal bounds of the polygon.

And oh yes, if the input point lies outside the entire bounding box of the cell space partitioning, it should also clamp and start the start from the closest cell to the point.

getClosestRegionAndPoint would be more useful as such, particularly for those google sketchup kind of snapping behaviours.

from yuka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.