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

Update Intersector.java #2132

Merged
merged 2 commits into from Jul 23, 2014

Conversation

@tavomaciel
Copy link
Contributor

tavomaciel commented Jul 19, 2014

Added method for getting intersection point for two 2D rays.

Added method for getting intersection point for two 2D rays.
@tavomaciel

This comment has been minimized.

Copy link
Contributor Author

tavomaciel commented Jul 19, 2014

Was looking for this today, and it wasn't implemented before on LibGDX.
For more info on how I came to this result, check: http://stackoverflow.com/a/565282/1091440

float difx = start2.x - start1.x;
float dify = start2.y - start1.y;
float d1xd2 = direction1.x * direction2.y - direction1.y * direction2.x;
if(d1xd2 == 0) {

This comment has been minimized.

Copy link
@dsaltares

dsaltares Jul 23, 2014

Member

Maybe compare to 0.0f instead?

This comment has been minimized.

Copy link
@davebaol

davebaol Jul 23, 2014

Member

I think the compiler does the cast for you. Not sure though. Should look into the byte code, but I'm too lazy :)

@dsaltares

This comment has been minimized.

Copy link
Member

dsaltares commented Jul 23, 2014

Besides the tiny comment, it looks good to me! Maybe wait for someone who actually worked on this area of Libgdx to decide.

float dify = start2.y - start1.y;
float d1xd2 = direction1.x * direction2.y - direction1.y * direction2.x;
if(d1xd2 == 0) {
return 0; //collinear

This comment has been minimized.

Copy link
@xoppa

xoppa Jul 23, 2014

Member

Probably better to use NaN or Inf, otherwise there's no way to distinguish the situation where start1 equals start2.

comparing direction cross product to `0.0f` instead of `0`;
now returning `Float.POSITIVE_INFINITY` in case they are collinear
@tavomaciel

This comment has been minimized.

Copy link
Contributor Author

tavomaciel commented Jul 23, 2014

@siondream other procedures in the same file are comparing floats to 0, instead of 0.0f, so I went to with the flow :P but I changed it on the last commit.

@tavomaciel

This comment has been minimized.

Copy link
Contributor Author

tavomaciel commented Jul 23, 2014

@xoppa commented on having a signature taking two Ray instances, but I cannot see the comment anymore (I received a notification on e-mail)

anyway: I didn't add it because the Ray class defines a 3D ray, and this method is probably only useful for 2D rays. I'm not sure if on the 3D space it really detects intersections, or if it gets concurrent lines, someone should test it.
Of course I could implement if you want it, and even implement versions taking floats. Just drop a comment so I can know what to do.

@xoppa

This comment has been minimized.

Copy link
Member

xoppa commented Jul 23, 2014

Thanks. Yeah I removed that comment directly after posting it, I was too hastily and didn't pay enough attention, sorry about that. Indeed it doesn't make sense for 3D.

@xoppa xoppa closed this Jul 23, 2014
@xoppa xoppa reopened this Jul 23, 2014
xoppa added a commit that referenced this pull request Jul 23, 2014
@xoppa xoppa merged commit d8e482f into libgdx:master Jul 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.