Click here to Skip to main content
15,886,919 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Jquery - Setting focus on Canvas Pin
AspDotNetDev7-Apr-13 13:10
protectorAspDotNetDev7-Apr-13 13:10 
GeneralRe: Jquery - Setting focus on Canvas Pin
Simon Lee Shugar7-Apr-13 21:34
Simon Lee Shugar7-Apr-13 21:34 
QuestionAJAX Javascript ShowModalDialogBox in IE 7 and above not working Pin
unniyadan28-Mar-13 20:53
unniyadan28-Mar-13 20:53 
AnswerRe: AJAX Javascript ShowModalDialogBox in IE 7 and above not working Pin
Prasad Khandekar11-Apr-13 3:44
professionalPrasad Khandekar11-Apr-13 3:44 
QuestionAJ Pin
unniyadan28-Mar-13 20:52
unniyadan28-Mar-13 20:52 
QuestionJquery JqGrid Pin
Member 962382927-Mar-13 2:30
professionalMember 962382927-Mar-13 2:30 
AnswerRe: Jquery JqGrid Pin
Jasmine250127-Mar-13 7:48
Jasmine250127-Mar-13 7:48 
QuestionBall to Ball collision handling Pin
SRJ9226-Mar-13 14:19
SRJ9226-Mar-13 14:19 
hi,
I have looked all over and can't find something that suits my needs... so here goes...

I am creating a snooker game in HTML 5 canvas and JavaScript and have now came to the part of resolving the ball to ball collisions.

So far I have this, which is great, it detects the cue ball hitting another ball:

JavaScript
function isColliding(ball){
var distance = Math.sqrt(((this.posX - ball.posX)*(this.posX - ball.posX)) + ((this.posY - ball.posY) * (this.posY - ball.posY)));
	
if (distance < this.radius + ball.radius){
//balls have collided now work out where they collided
					
var collisionPointX = ((this.posX * ball.radius) + (ball.posX * this.radius)) / (this.radius + ball.radius);

var collisionPointY = ((this.posY * ball.radius) + (ball.posY * this.radius)) / (this.radius + ball.radius);
					
ball.speed = this.speed;
					
this.directionX = Math.cos(?);
					
this.directionY = Math.sin(?);
					
ball.directionX = Math.cos(?);
					
ball.directionY = Math.sin(?);
							
}
							
}


However I need to know how do I work out the Math.cos and Math.sin for the balls to move in a direction that is expected (using elastic collision), when they collide?

Thanks for help in advance..
Steve
AnswerRe: Ball to Ball collision handling Pin
Kenneth Haugland26-Mar-13 15:29
mvaKenneth Haugland26-Mar-13 15:29 
GeneralRe: Ball to Ball collision handling Pin
dusty_dex26-Mar-13 21:00
dusty_dex26-Mar-13 21:00 
GeneralRe: Ball to Ball collision handling Pin
Kenneth Haugland26-Mar-13 22:01
mvaKenneth Haugland26-Mar-13 22:01 
AnswerRe: Ball to Ball collision handling Pin
SRJ9227-Mar-13 4:04
SRJ9227-Mar-13 4:04 
QuestionAjax request call using jquery Pin
Raj G121-Mar-13 2:49
Raj G121-Mar-13 2:49 
GeneralRe: Ajax request call using jquery Pin
dusty_dex21-Mar-13 8:33
dusty_dex21-Mar-13 8:33 
GeneralRe: Ajax request call using jquery Pin
jkirkerx21-Mar-13 9:24
professionaljkirkerx21-Mar-13 9:24 
GeneralSlide show Pin
Tichaona J21-Mar-13 0:10
Tichaona J21-Mar-13 0:10 
GeneralRe: Slide show Pin
Graham Breach21-Mar-13 1:37
Graham Breach21-Mar-13 1:37 
GeneralRe: Slide show Pin
jkirkerx21-Mar-13 7:55
professionaljkirkerx21-Mar-13 7:55 
GeneralRe: Slide show Pin
alisener198022-Mar-13 9:41
alisener198022-Mar-13 9:41 
QuestionA question to dust_dex Pin
Hakan Bulut20-Mar-13 22:51
Hakan Bulut20-Mar-13 22:51 
AnswerRe: A question to dust_dex Pin
dusty_dex21-Mar-13 5:29
dusty_dex21-Mar-13 5:29 
GeneralRe: A question to dust_dex Pin
Hakan Bulut24-Mar-13 21:13
Hakan Bulut24-Mar-13 21:13 
GeneralRe: A question to dust_dex Pin
dusty_dex24-Mar-13 21:53
dusty_dex24-Mar-13 21:53 
GeneralRe: A question to dust_dex Pin
Hakan Bulut24-Mar-13 23:47
Hakan Bulut24-Mar-13 23:47 
GeneralRe: A question to dust_dex Pin
Hakan Bulut25-Mar-13 1:11
Hakan Bulut25-Mar-13 1:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.