Click here to Skip to main content
15,915,752 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: validating candian postal codes [solved] Pin
jkirkerx1-Apr-13 7:20
professionaljkirkerx1-Apr-13 7:20 
QuestionTime and date Pin
Tichaona J31-Mar-13 4:15
Tichaona J31-Mar-13 4:15 
AnswerRe: Time and date Pin
dusty_dex31-Mar-13 4:41
dusty_dex31-Mar-13 4:41 
QuestionJquery - Setting focus on Canvas Pin
Simon Lee Shugar29-Mar-13 2:54
Simon Lee Shugar29-Mar-13 2:54 
AnswerRe: Jquery - Setting focus on Canvas Pin
Jasmine250129-Mar-13 6:55
Jasmine250129-Mar-13 6:55 
GeneralRe: Jquery - Setting focus on Canvas Pin
Simon Lee Shugar3-Apr-13 12:51
Simon Lee Shugar3-Apr-13 12:51 
AnswerRe: Jquery - Setting focus on Canvas Pin
jkirkerx30-Mar-13 18:57
professionaljkirkerx30-Mar-13 18:57 
AnswerRe: Jquery - Setting focus on Canvas Pin
Dennis E White2-Apr-13 5:57
professionalDennis E White2-Apr-13 5:57 
GeneralRe: Jquery - Setting focus on Canvas Pin
jkirkerx2-Apr-13 6:28
professionaljkirkerx2-Apr-13 6:28 
GeneralRe: Jquery - Setting focus on Canvas Pin
Dennis E White2-Apr-13 6:35
professionalDennis E White2-Apr-13 6:35 
GeneralRe: Jquery - Setting focus on Canvas Pin
jkirkerx2-Apr-13 6:38
professionaljkirkerx2-Apr-13 6:38 
GeneralRe: Jquery - Setting focus on Canvas Pin
Dennis E White2-Apr-13 6:42
professionalDennis E White2-Apr-13 6:42 
GeneralRe: Jquery - Setting focus on Canvas Pin
Simon Lee Shugar3-Apr-13 12:50
Simon Lee Shugar3-Apr-13 12:50 
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 

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.