Explanation of the parameters in the line intersection code

I am trying to understand a C code that moves the mesh nodes for each time step and i am totally struck on the parameters t1 and t2 please help me sorting this out. So here is what the function gets (Xa,Ya) (Xb,Yb) (Xc,Yc) and (Xd,Yd) where (Xc,Yc) is the origin (0,0) about which mesh rotates now i have a function that calculates t1 and t2 and (i think t1 is the parameter in barycentre form of line that gives intersection point between two line formed by (Xa,Ya)(Xb,Yb) and (Xc,Yc)(Xd,Yd)) and i have no idea what t2 is...

The code is

static void find_t(real xa, real ya, real xb, real yb,
real xc, real yc, real xd, real yd,
real *t1, real *t2, int * flag)
{
if((xd==xc)&&(xb!=xa))
{
if(yd==yc)
{
Message0("\nc and d are the same points-aborting!!!\n");
exit(0);
}
(*flag) = 2;
(*t1) = (xc-xa)/(xb-xa);
(*t2) = ((yb-ya)*(*t1)-(yc-ya))/(yd-yc);
}
else if((xd!=xc)&&(xb==xa))
{
if(yb==ya)
{
Message0("\na and b are the same points-aborting!!!\n");
exit(0);
}
(*flag) = 2;
(*t2) = (xc-xa)/(xc-xd);
(*t1) = ((yd-yc)*(*t2)+(yc-ya))/(yb-ya);
}
else if((xd==xc)&&(xb==xa))
{
(*flag) = 0;
return;
}
else
{
real k1, k2;
k1 = (yd-yc)/(xd-xc);
k2 = (yb-ya)/(xb-xa);
if(fabs(k2)>=fabs(k1))
{
if(k1==k2)
{
(*flag) = 0;
return;
}
(*flag) = 1;
(*t1) = (-k1*(xc-xa)+(yc-ya))/((yb-ya)-k1*(xb-xa));
(*t2) = ((xb-xa)*(*t1)-(xc-xa))/(xd-xc);
}
else
{
(*flag) = 1;
(*t2) = (-k2*(xc-xa)+(yc-ya))/(-(yd-yc)+k2*(xd-xc));
(*t1) = ((xd-xc)*(*t2)+(xc-xa))/(xb-xa);
}
}
return;
}


and the value returned is used to update the mesh point if the following condition is satisfied

  if(((flag==1)||(flag==2))&&(t1<=1+cal_small_number(j))&&(t1>=-cal_small_number(j))&&(t2>=0))

{
(*x) = (1-t1)*pt1[0] + t1*pt2[0];
(*y) = (1-t1)*pt1[1] + t1*pt2[1];
return;

}


please can some recognize what t2 is and correct me if my thought about t1 is wrong,The point(*x,*y) i get is the intersection point between two lines

• Whaaa~attt. No comments? 2-character variable names? Who wrote this code? I would like to ask them some questions.
– Anko
Commented Oct 30, 2015 at 18:29
• Looks like t1 is the fraction along the line segment AB where it intersects segment CD, and t2 is the fraction along CD where this happens. So A + t1 * (B - A) = C + t2 * (D - C) - but I haven't yet worked out the math to confirm whether this interpretation is correct. Commented Oct 30, 2015 at 18:38
• T and t2 is usually a parameter in parametric equation - and in line segment intersection it makes sense. Commented Oct 30, 2015 at 19:52
• Thanks for all to comment,@Anko Yes there are no comments and this code was written some 15 years ago by ANSYS people...@DMGregory I understand your comments for t1 but i dont get what you meant for t2 could you please spend some time explaining me at your convenience please...@Wondra please could you explain more on that Commented Oct 30, 2015 at 20:15
• @DMGregory you are correct just tried with some generic points and i am able to locate the intersection point from a and d,could you please tell me how this formula works or show some books i can read to get it thanks a ton it took so long for me to get to this point :( Commented Oct 30, 2015 at 20:39