///////////////////////////////////////////////////////////////////////////////////////////////////////
tt2767
Disclaimer: This document is subject to the following agreement free reprint-non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0
To view the update and discussion of this article, please click here: http://blog.csdn.net/tt2767
Link is deleted please Baidu: CSDN tt2767
///////////////////////////////////////////////////////////////////////////////////////////////////////
Key: This problem to understand after the main set of templates to calculate.
1. Use dot product (dot) to determine if the circle is not
2. The distance from the origin to the straight line is obtained by the cross product.
3. Two situations: rebound or no impact after impact
4. Remember to keep only 3 decimal places
#include <sstream>#include <string>#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <math.h>#include <iterator>#include <map>#include <stack>#include <queue>#include <set>#include <list>#include <functional>#include <numeric>using namespace STD;inline intLowbit (intx) {returnx& (-X);}structpoint{Doublex, y; Point (DoubleXDoubleY): X (x), Y (y) {} point () {}};typedefPoint Vector;DoubleCross (vector A, vector b) {returna.x*b.y-a.y*b.x;}DoubleDot (vector A, vector b) {returnA.X*B.X+A.Y*B.Y;}typedef Long Long intLL;Const DoubleEPS =1e-9;Const intINF =0x3f3f3f3f;Const Long DoublePI =ACOs(0.0) *2.0;Const intN =100009;intMain () {DoubleRm,r,r,x,y,vx,vy; while(scanf("%LF%LF%LF%LF%LF%LF%LF", &rm,&r,&r,&x,&y,&vx,&vy) = =7) {point P (x, y); Vector S (0-X,0-y), V (vx,vy); Rm+=r; R+=r;DoubleVel =sqrt(V.X*V.X+V.Y*V.Y);DoubleD =fabs(Cross (S,V))/vel;if(Dot (s,v) < EPS | | d-r > EPS)printf("0.000\n");Else if(D-rm > EPS)printf("%.3lf\n",2*sqrt(r*r-d*d)/vel);Else printf("%lf\n",2*(sqrt(r*r-d*d)-sqrt(rm*rm-d*d)) /vel); }return 0;}
Copyright NOTICE: This article for Bo Master original article, allow non-commercial reprint, reprint must note name author (CSDN tt2767) and this blog link: http://blog.csdn.net/tt2767.
Zoj3728_collision (Simple computational geometry)