Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Intersection of 2 lines
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00479322
Message ID:
00479513
Vues:
32
Roi,

The following will should give you what you want however you need to turn it into VFP source. The pointers passed into xi and yi will hold the coords of the intersection.
void Intersect_Lines(float x0,  float y0, float x1, float y1,
                     float x2,  float y2, float x3, float y3,
                     float *xi, float *yi)
{
// Constants of linear equations.
float a1, b1, c1;       
float a2, b2, c2;

// The inverse of the determinant of the coefficient matrix
float det_inv;  

// The slopes of each line.
float m1, m2;    

// Compute slopes, note the cludge for infinity.
if ((x1 - x0)!= 0)
   m1 = (y1 - y0) / (x1 - x0);
else
   m1 = (float)1e + 10;   

if ((x3 - x2)!= 0)
   m2 = (y3 - y2) / (x3 - x2);
else
   m2 = (float)1e + 10; 

// Compute constants.
a1 = m1;
a2 = m2;

b1 = -1;
b2 = -1;

c1 = (y0 - m1 * x0);
c2 = (y2 - m2 * x2);

// Compute the inverse of the determinate.
det_inv = 1 / (a1 * b2 - a2 * b1);

// Use Kramers rule to compute xi and yi.
*xi = ((b1 * c2 - b2 * c1) * det_inv);
*yi = ((a2 * c1 - a1 * c2) * det_inv);
} 
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform