Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075919 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:15:23 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Bizarre issue in segment/convex poly intersection
Pages: [1]
Print
Author Topic: Bizarre issue in segment/convex poly intersection  (Read 557 times)
celloe
Level 0
*


View Profile
« on: September 14, 2013, 05:57:07 PM »

I have a line segment defined by its points p0 and p1, and a polygon defined by a set of points, guaranteed to be convex. I followed this article to get my intersection test up and running okay - http://geomalgorithms.com/a13-_intersect-4.html and it was working great, until I started using it in different cases.

I'm using AS3, and currently the test fails in seemingly random cases, when my line segment is oriented in a particular way, and, oddly enough, sometimes only works when wrapped inside a time-based function such as an ENTER_FRAME call or Timer.


It's hard to show from a demo alone as it's purely based on tweaking values and seeing what works, but here's the code: http://pastebin.com/tejrZjUw

And my current results:


Any ideas?.. Been staring at this for quite a while and can't think of what causes it.
Logged
Will Vale
Level 4
****


will@secondintention.com
View Profile WWW Email
« Reply #1 on: September 15, 2013, 07:50:47 PM »

I'm not an AS3 person so I don't know what the implications are for unintialised variables, but it looks like you have a case where t can be uninitialised when you're computing the entry and exit points.

In your small D branch (close to edge?) you continue the loop skipping the calculation of t if N is positive. You could have this happen on all iterations, in which case you wind up exiting the loop and using the undefined value of t.

Not sure if that *is* happening in your case, but worth checking.

If AS3 initialises everything, this is a non-issue. Likewise if the maths mean this situation never comes up for all points it's a non-issue, but maybe it'll offer a clue.

W
Logged
ChevyRay
Level 2
**



View Profile WWW Email
« Reply #2 on: September 16, 2013, 12:07:21 PM »

Default value for Number types is NaN, so that could be your problem.
Logged

Unity Patterns - Tools & Resources for Unity Developers
FlashPunk - 2D Flash Game Engine
celloe
Level 0
*


View Profile
« Reply #3 on: September 18, 2013, 01:07:48 PM »

Both of you lead me directly to the clue that helped me figure it out! Turns out it worked when called inside the enterFrame function as I'd defined SMALL_NUM below all my functions, so at the time of first calculation it was NaN. So I was getting a divide by zero.

Thanks for the help!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic