Line - Line Intersect

from Or........../Work 2009. 8. 27. 14:50

2D Line - Line Intersect

IntersectLineLine(D3DXVECTOR3 Line1Start, D3DXVECTOR3 Line1End, D3DXVECTOR3 Line2Start, D3DXVECTOR3 Line2End)

{

  float A1, B1, C1, A2, B2, C2, M1, M2, DetInv;

  if ((Line1End.x - Line1Start.x) != 0)
   M1 = (Line1End.y - Line1Start.y) / (Line1End.x - Line1Start.x);
  else
   FALSE;

  if ((Line2End.x - Line2Start.x) != 0)
   M2 = (Line2End.y - Line2Start.y) / (Line2End.x - Line2Start.x);
  else
   FALSE;

  // Compute constants
  A1 = M1;
  A2 = M2;

  B1 = -1;
  B2 = -1;

  C1 = (Line1Start.y - M1 * Line1Start.x);
  C2 = (Line2Start.y - M2 * Line2Start.x);

  // Compute the inverse of the determinate
  DetInv = 1 / (A1 * B2 - A2 * B1);

  // Use Kramers rule to compute Intersect Point
  float IntersectX, IntersectY;
  IntersectX = (B1 * C2 - B2 * C1) * DetInv;
  IntersectY = (A2 * C1 - A1 * C2) * DetInv;

  return TRUE;

} // end Intersect_Lines

'Or.......... > Work' 카테고리의 다른 글

Scene Graph Rendering  (0) 2009.08.27
kd-tree Introduction  (0) 2009.08.27
Grass Rendering  (0) 2009.08.27
Water Rendering  (0) 2009.08.27
Flight Simulator : HUD - LCOSS  (0) 2009.08.27
,