-
Notifications
You must be signed in to change notification settings - Fork 53
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
point of collision #29
Comments
Getting the point of collision would be super easy for some of these (point/point, for example) but very difficult for most of them. The math gets way more complex and the code would be quite a bit slower, which is why the positions of collision isn't included here, sorry! For normal direction, you mean the direction that the object was moving when it collided with another? |
When I saw this example I could not find the code for the red points, so I asked this question. Ray cast hit : in 2D I think this method will have a quick result The red dot source code is very useful to me and solve all 🥇 Your code is very simple to learn and great! |
Ah, those will actually be really easy! If you look in the collision functions, they give us the For example, here's
And this is the part you want!
|
Thank you very much, even very simple things can be useful 😃👍
…On Wed, Mar 2, 2022, 8:04 PM Jeff Thompson ***@***.***> wrote:
Ah, those will actually be really easy! If you look in the collision
functions, they give us the x/y coordinates. I don't send them back to
the main draw() but you could definitely modify the function to return a
vector instead of true/false.
For example, here's line/line:
// LINE/LINE
boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
// calculate the distance to intersection point
float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
// if uA and uB are between 0-1, lines are colliding
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
// optionally, draw a circle where the lines meet
float intersectionX = x1 + (uA * (x2-x1));
float intersectionY = y1 + (uA * (y2-y1));
fill(255,0,0);
noStroke();
ellipse(intersectionX,intersectionY, 20,20);
return true;
}
return false;
}
And this is the part you want!
float intersectionX = x1 + (uA * (x2-x1));
float intersectionY = y1 + (uA * (y2-y1));
—
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APJCR4QA3P3XKRONL3GNA43U56KCVANCNFSM5PWQ6W3Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hello ! How can i found position of collision when is it true ?
also i need normal direction .
The text was updated successfully, but these errors were encountered: