0

This is part of a code from a user defined function in (fluent-CFD software) to deform the mesh.

The comment says it finds the intersection between two lines.

My questions are:

1.Does the value t1 and t2 represent the X and Y coordinates of intersection point?

2.How does it find the intersection?(Help me with math I cannot recognize the formula written for (*t1 and *t2)). It would be great if you can give some geometrical explanation of the formula.

    # include "udf.h"
    # include "dynamesh_tools.h"
   /* # define DEBUG */
    #if RP_DOUBLE
    #define SMALL_NUMBER 1e-8
    #else
    #define SMALL_NUMBER 1e-4
    #endif
    extern real RPM;
    extern int Num_Layers;

    /* Find the intersection t1 and t2 for two lines*/
    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;
           }
Blitz
  • 5,521
  • 3
  • 35
  • 53
  • Hi joseph thanks for looking my question.This is a C code but it is customized for the usage with fluent software.I dont get the math for finding the intersection between two nodes.that t1 and t2 are said to hold the intersection value between two lines in the comment section but i dont think so.please help me for sorting this out – fascinatedbyCFD Oct 29 '15 at 09:30
  • Ok, I am inspecting your code. – Jose Rodriguez Oct 29 '15 at 13:58
  • Hi i realized that t1 and t2 are unitless so i think message line they typed must be wrong and t1 and t2 must be some parameter that represent the barycentric form of line (source:http://www.csee.umbc.edu/~olano/class/435-04-2/bary.pdf) but i cannot find the formula to get the parameter t – fascinatedbyCFD Oct 29 '15 at 16:35
  • Is hard know what are t1 and t2? I can modify the code to detect the intersection point of two lines if they are not parallels. – Jose Rodriguez Oct 29 '15 at 16:50
  • Really thanks for the help, but i have a working code(which i did not write :)) and i am trying to understand what the code does and this is the place (what t1 and t2 outputs is unknown) so i cannot further go on reading the code,i felt this should be some barycentric coordinates (any help in determining the parameter for barycentric form of line would be great help) – fascinatedbyCFD Oct 29 '15 at 17:05
  • hi did you get any idea meanwhile i started learning about barycentric coordinates and t1 in some sense represent whether the third point d is located between a and b or not but i donot get what t2 represents thanks in advance – fascinatedbyCFD Oct 30 '15 at 17:05

0 Answers0