| 09-15-2006, 07:08 PM | #2 |
Arctangent actually. Atan(yVel/xVel) will give you the direction of the arrow in radians. |
| 09-15-2006, 07:22 PM | #3 |
I dont understand, could you explain further? If its towards the angle before hitting, then im sorry i said the question wrong. |
| 09-15-2006, 07:47 PM | #4 |
So you have a person/circle who is much more massive than a ball/circle of finite size? All 2d I assume. If the person is immobile and the collision is lossless, then the velocity of the ball will be reflected across the line going from the center of one circle to the center of the other. The easiest way to do this is rotate your velocity vector into the frame of normal/tangential to the collision surface, negate the normal component, then rotate back. This is just a similarity transform, so you can multiply out the transformation to save some ops and probably find some other nice explanation for what is going on. Take t to be the angle between the y axis and the line between the two circles, or pi/2+atan2(r2y-r1y,r2x-r1x). {vx_after,vf_after} = {{cos(t),-sin(t)},{sin(t),cos(t)}} . {{1,0},{0,-1}} . {{cos(t),sin(t)},{-sin(t),cos(t)}} . {vx_before, vy_before} So multiply out those three matrices and you'll have a nice expression for before to after. Edit: Oops, I meant negate normal component, not tangential. Matrices are still OK, since I also mixed up which was which there. To below: No, you're completely right too. When you multiply out the matrices you end up with a rotation by twice the angle from the normal which is another way of saying take the difference and add it to the other side. It's easy to see if you use complex arithmetic instead of matrices. |
| 09-15-2006, 08:00 PM | #6 |
Pipe, thanks alot, but unfortunatly, i dident understand half of that, my young maths skills havent advanced that far. Naak, could you give me a example? Maybe a function that returns it, im not sure about velocity and how to get its x/y, and how to implement a function that would do that. I thought, because its a round circle, its not always reflected on the incoming angle, because depending on where it hits, and the angle between the arrow and the circle effects the outgoing arrow. I wasent sure =/. EDIT: To give me infomation, basically theirs going to be ball's moving on the floor, at a set speed, they move in straight lines, until they hit something and bounce somewhere else, but im just not sure about how to get the new angle. |
| 09-15-2006, 09:09 PM | #7 |
The law of reflection will be true regardless of the axes, you just need to be sure that you're using the correct axis for the normal. In the case of a perfect circle, the axis along the angle from the center of the circle to the point of impact should be the normal for the tangent to the point of impact. Edit: Here's a function that I think should demonstrate what I mean. I'm just giving all the variables in the parameters, I don't know how you plan to handle it. I think this should work, the I'm not certain how if Atan returns value in degrees or radians. JASS:function GetAngleOfReflection takes real ballXVel, real ballYVel, real impactX, real impactY, real centerX, real centerY returns real local real ballDirection = Atan(ballYVel / ballXVel) local real normalDirection = Atan( (impactX - centerX) / (impactY - centerY) ) local real incidenceAngle = normalDirection - ballDirection local real reflectedAngle = normalDirection + incidenceAngle return reflectedAngle endfunction |
| 09-17-2006, 04:55 PM | #8 |
Sorry for the late reply, i'v been away since friday night. Thanks for the function, i'll test it in a moment, but one more question, what are the variables ballXVel, ballYVel, impactX, impactY, centerX and centerY. I can guess impactX/Y but im not sure about the Vel and centers. |
| 09-17-2006, 04:58 PM | #9 |
X and Y velocity components of the object that's flying to the circle. X and Y values of the center of the circle. |
| 09-18-2006, 03:18 PM | #10 |
Velocity as in the objects speed? |
| 09-18-2006, 03:21 PM | #11 |
looks liek someone is trying to make pinball |
| 09-18-2006, 03:22 PM | #12 | |
Quote:
Not quite :), but nearly. |
| 09-18-2006, 04:09 PM | #13 | |
Quote:
Yes and no, for all considerations in this situation you can treat it as speed since you're handling direction as a separate issue. |
| 09-18-2006, 05:11 PM | #14 |
Thanks so much for this help. I'v added rep to you and Pipe. |
