question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

isPointInTriangle returning true when it shouldn't

See original GitHub issue

Issue details

Intersector#isPointInTriangle fails for points lying on the plane of the triangle but not within it due to a floating-point rounding error in some cases.

The last check if the function:

if (ab * bc - ac * bb < 0) return false;

is sometimes having its arithmetic being rounded to 0.0 causing the function to return true even though the answer should be false.

Reproduction steps/code

Intersector.isPointInTriangle(
                new Vector3( -5120.8345f,8946.126f,-3270.5813f),

                new Vector3(50.008057f, 22.20586f, 124.62208f),

                new Vector3( 62.282288f, 22.205864f, 109.665924f),

                new Vector3(70.92052f, 7.205861f, 115.437805f))

will return true even though the point is clearly not in the triangle.

Version of libGDX and/or relevant dependencies

Tested on version 1.10.0 however should still be failing on all versions

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tylerhasmancommented, Jun 16, 2022

Looks like this new function that @tommyettinger created is working well. I’ll try to remember and create a pull request tonight

0reactions
tommyettingercommented, Jun 17, 2022

Hooray for numeric stability!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Find if a point is within a triangle - Rosetta Code
Assume points are on a plane defined by (x, y) real number coordinates. Given a point P(x, y) and a triangle formed by...
Read more >
Diff - platform/frameworks/base - Google Git
@param event The key event to handle. - * @return {@code true} if the event was handled. - */ - public boolean handleKeyEventIfNecessary(KeyEvent...
Read more >
Unity Raycast always returning true - Stack Overflow
Could the ray be hitting my character collider? Yes, that is possible. This is actually problem that can easily be solve with Debug.Log...
Read more >
doc - Apple Open Source
(_web_NSURLResponse_MIMEType): Either return the actual MIME type of the response, ... when running under Mail, the implicit <head> shouldn't be created.
Read more >
Purpose of return false, new, null, true.... - Unity Forum
In general, you must return an object of the type which your function is declared as returning. i.e.. Code (csharp):. public int foo(){ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found