Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

http://www.eskimoblood.de

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Line intersection

the function gives the point where 2 lines intersect

   1  
   2  float[] checkIntersection(float lineAx1,float lineAy1,float lineAx2,float lineAy2,float lineBx1,float lineBy1,float lineBx2,float lineBy2){
   3    float aM, bM, aB, bB, isX=0, isY=0;
   4    if((lineAx2-lineAx1)==0){
   5      isX=lineAx1;
   6      bM=(lineBy2-lineBy1)/(lineBx2-lineBx1);
   7      bB=lineBy2-bM*lineBx2;
   8      isY=bM*isX+bB;
   9    }
  10    else if((lineBx2-lineBx1)==0){
  11      isX=lineBx1;
  12      aM=(lineAy2-lineAy1)/(lineAx2-lineAx1);
  13      aB=lineAy2-aM*lineAx2;
  14      isY=aM*isX+aB;
  15    }
  16    else{
  17      aM=(lineAy2-lineAy1)/(lineAx2-lineAx1);
  18      bM=(lineBy2-lineBy1)/(lineBx2-lineBx1);
  19      aB=lineAy2-aM*lineAx2;
  20      bB=lineBy2-bM*lineBx2;
  21      isX=max(((bB-aB)/(aM-bM)),0);
  22      isY=aM*isX+aB;
  23    }
  24    float[] r={
  25      isX,isY  };
  26    return r; 
  27  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS