Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[geom-isec] pointInSegment2 fails when line is perpendicular #84

Closed
acarabott opened this issue May 16, 2019 · 2 comments
Closed

[geom-isec] pointInSegment2 fails when line is perpendicular #84

acarabott opened this issue May 16, 2019 · 2 comments

Comments

@acarabott
Copy link
Contributor

If a[0] === b[0] or a[1] === b[1] then we get a divide by zero, and will always return false.

const p = [ 5, 10];
const a = [ 0, 10];
const b = [10, 10];

const result = pointInSegment2(p, a, b); // false

Also, the check !(tx < 0 || tx > 1 || ty < 0 || ty > 1) doesn't take eps into account, so the following will return false

const p = [5, 2];
const a = [0, 0];
const b = [10, 1];
const eps = 3;

as

const tx = 0.5; // (5 − 0) / (10 − 0)
const ty = 2; // (2 - 0) / (1 - 0)

Math.abs(tx - ty) <= eps; // true (1.5 <= 3)

// but ty > 1 so will return false

Pull request coming...

acarabott pushed a commit to acarabott/umbrella that referenced this issue May 16, 2019
when ax === bx or ay === by, a divide by zero was caused, returning false
now takes the eps param into account with small segments

fixes thi-ng#84
@acarabott
Copy link
Contributor Author

On seconds thoughts, the change to epsilon is not as straightforward as I thought: with a totally horizontal line and an epsilon of (e.g.) 10, with a point on the line vertically, but outside of it horizontally, it will still return true.

a = [ 0, 0]               
b = [10, 0]      
p = [15, 0]
eps = 10

a--------------------b      p


Math.abs(tx - ty): 1.5
tx: 1.5
ty: 0
result: true

Input appreciated! Perhaps this approach would work, but would be more expensive: http://paulbourke.net/geometry/pointlineplane/

@postspectacular
Copy link
Member

Just linking PR comment here: #85 (comment)

postspectacular added a commit that referenced this issue May 22, 2019
* develop:
  build: remove unintended ecs pkg
  Publish
  refactor(geom-voronoi): update pointInSegment call
  feat(geom): add Plane, Quad3 factories & ops
  fix(geom-isec): fix #84, update pointInSegment, add tests
  feat(geom-isec): add ray-plane, plane-plane fns, update readme
  fix(geom-closest-point): flip sign of plane W component, extract distToPlane()
  feat(math): add sigmoid / sigmoid11 fns
  feat(associative): add sparseSet factory fn
  fix(pointfree): update safeMode handling
  feat(matrices): add outerProduct for vec 2/3/4
  docs(math): minor update doc strings
  feat(math): add extrema & crossing fns and Crossing enum
  refactor(associative): minor updates ArraySet
  feat(associative): add SparseSet8/16/32
  refactor(vector-pools): update Type imports
  refactor(malloc): remove Type enum, SIZEOF
  feat(api): add Type enum, IntArray, UIntArray, FloatArray, SIZEOF
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

No branches or pull requests

2 participants