-----------------------------------------------------------------------------------------
La original
CheckIntersection
//xc, yc - are the circle's center coords
//x1,y1 - x2,y2
if(x1 - x2 == 0) //if the incline is 0 we need diff equation
for i = y1 to y2
if(sqrt((xc - x1)^2 + (yc - i)^2) <= R) return true;
for i = x1 to x2
curry = ((y1 - y2)/(x1 - x2))*(i - x1) + y1
if(sqrt((xc - i)^2 + (yc - curry)^2) <= R) return true;
//x2,y2 - x3,y3
if(x2 - x3 == 0) //incline 0
for i = y1 to y2
if(sqrt((xc - x2)^2 + (yc - i)^2) <= R) return true;
for i = x2 to x3
curry = ((y2 - y3)/(x2 - x3))*(i - x2) + y2
if(sqrt((xc - i)^2 + (yc - curry)^2) <= R) return true;
//x3,y3 - x1,y1
if(x3 - x1 == 0) //incline 0
for i = y1 to y2
if(sqrt((xc - x1)^2 + (yc - i)^2) <= R) return true;
for i = x3 to x1
curry = ((y3 - y1)/(x3 - x1))*(i - x3) + y3
if(sqrt((xc - i)^2 + (yc - curry)^2) <= R) return true;
return false; //if no such point found return false
-------------------------------------------------------------------------------------------------
como la puse en java
Código:
public boolean triangulocho(Pelota redonda,Triangulo tria){ //xc, yc - are the circle's center coords //x1,y1 - x2,y2 if(tria.x1 - tria.x2 == 0) { //if the incline is 0 we need diff equation for (int i=tria.y1;i<tria.y2;i++){ if (sqrt((redonda.centrox - tria.x1)^2 + (redonda.centroy - i)^2) <= redonda.radio){return true;}} } for (int i=tria.x1;i<tria.x2;i++){ int curry = ((tria.y1 - tria.y2)/(tria.x1 - tria.x2))*(i - tria.x1) + tria.y1; if(sqrt((redonda.centrox - i)^2 + (redonda.centroy - curry)^2) <= redonda.radio) {return true;} } //x2,y2 - x3,y3 if(tria.x2 - tria.x3 == 0) { //incline 0 for(int i=tria.y1;i<tria.y2;i++){ if(sqrt((redonda.centrox - tria.x2)^2 + (redonda.centroy - i)^2) <= redonda.radio) {return true;} }} for (int i=tria.x2;i<tria.x3;i++){ int curry = ((tria.y2 - tria.y3)/(tria.x2 - tria.x3))*(i - tria.x2) + tria.y2; if(sqrt((redonda.centrox - i)^2 + (redonda.centroy - curry)^2) <= redonda.radio) {return true;} } //x3,y3 - x1,y1 if(tria.x3 - tria.x1 == 0) { //incline 0 for (int i=tria.y1;i<tria.y2;i++){ if(sqrt((redonda.centrox - tria.x1)^2 + (redonda.centroy - i)^2) <= redonda.radio) {return true;} } for (int i=tria.x3;i<tria.x1;i++) { int curry = ((tria.y3 - tria.y1)/(tria.x3 - tria.x1))*(i - tria.x3) + tria.y3; if(sqrt((redonda.centrox - i)^2 + (redonda.centroy- curry)^2) <= redonda.radio) {return true;} }} return false; //if no such point found return false }