Intersection of Pair of Lines in the Goven Order of N Lines

Submitted by: 
Language: 
Visitors have accessed this post 132 times.

This project will teach you how to get the intersection of pair of lines in the goven order of N lines. This is very simple project. Download project to see the full source code.

Please don't forget to like my page.

  1. #include<stdio.h>
  2. #include<ctype.h>
  3. #include<conio.h>
  4. #include<stdlib.h>
  5. int i=0;
  6. int a1=0 , b1=0 ,c1=0;int K=0;
  7. int detA =0 , det1 =0 , det2=0 ;int SIZE=0;
  8. float *x,*y ; int lines=0;int p=0,q=0,r=0,s=0;
  9. float x_cor =0 , y_cor =0;
  10.  
  11. struct COF {
  12. int a =0,b=0,c=0,k=0;
  13. int count =0;
  14. struct COF *next;
  15. };
  16.  
  17. struct POINT
  18. {
  19. float x_cord =0 , y_cord=0; int count =0; struct POINT *next;
  20. };
  21.  
  22. void CREATE (POINT *A)
  23. { A=(POINT *) malloc ( sizeof(POINT));return;
  24. }
  25.  
  26.  
  27. void CheckPoint(float cordx , float cordy , POINT *B)
  28. {
  29. int TESTX=0 ,TESTY=0;
  30. int FLAGX =0,FLAGY=0 ,STATUS =0;
  31.  
  32.  
  33.  
  34.  
  35. i=0;
  36. printf("Entering to CheckPoint PRESS ANY KEY \n");getch();
  37. do
  38. {
  39. printf("i== %d \n",i);
  40. if( (B->x_cord <=cordx && B->next->x_cord >= cordx ) || (B->next->x_cord <= cordx && B->x_cord >=cordx ) ) { TESTX=1;}
  41.  
  42.  
  43.  
  44.  
  45. if( (B->y_cord <=cordy && B->next->y_cord >= cordy ) || (B->next->y_cord <= cordy && B->y_cord >=cordy ) ) { TESTY=1;}
  46.  
  47.  
  48.  
  49.  
  50. B=B->next;
  51.  
  52. i++;
  53.  
  54.  
  55. }
  56.  
  57. while ( B->next->count!=1 );
  58.  
  59. printf("EXIT FROM DO WHILE \n");
  60.  
  61. printf("TESTX= %d TESTY= %d \n", TESTX ,TESTY);
  62.  
  63. if(TESTX==1 && TESTY==1 ) { printf("POINT IS INSIDE \n") ; }
  64. else { printf("POINT IS OUT SIDE \n"); }
  65.  
  66. return;
  67.  
  68. }
  69.  
  70. int main(void)
  71.  
  72. {
  73.  
  74.  
  75. struct COF *P;
  76. P=(COF *) malloc(sizeof(COF));
  77. struct COF *REF;
  78. REF=(COF *) malloc(sizeof(COF));
  79. REF=P;
  80.  
  81. printf("Number of lines N= ");
  82. scanf("%d",&lines);
  83.  
  84. POINT *XY ,*REFPOINT ;
  85. REFPOINT=(POINT *) malloc ( sizeof(POINT));
  86. for (i=0;i<lines ;i++)
  87. { if(i==0) {
  88. XY=(POINT *) malloc ( sizeof(POINT));REFPOINT=XY; }
  89.  
  90.  
  91. else {
  92.  
  93. if(i!=lines-1)
  94.  
  95. {
  96. XY->next=(POINT *) malloc ( sizeof(POINT));
  97. XY=XY->next;
  98. }
  99. else {XY->next=(POINT *) malloc ( sizeof(POINT));
  100. XY->next=REFPOINT;
  101. }
  102. }
  103.  
  104.  
  105. }
  106.  
  107.  
  108.  
  109.  
  110. x=(float *) malloc(lines*sizeof(float));
  111. y=(float *) malloc(lines*sizeof(float));
  112.  
  113.  
  114. if (x==NULL || y==NULL ) { printf(" X OR Y IS NOT CREATED \n");
  115. }
  116.  
  117.  
  118.  
  119. for ( i=0;i<lines ; i++ )
  120.  
  121. {
  122. printf("Enter the Coficients of %d th line \n", i+1 );
  123. printf("Enter a[%d] = ", i);
  124. scanf("%d",&a1);
  125. printf("Enter b[%d] = ",i);
  126. scanf("%d",&b1);
  127. printf("Enter c[%d] = ",i);
  128. scanf("%d", &c1);
  129. P->a=a1; P->b=b1;P->c=c1 ;P->k=-1*c1;P->count=i;
  130. a1=0 ; b1=0 ;c1=0;
  131. P->next=(COF *) malloc(sizeof(COF));
  132. if(i==lines-1) { P->next=REF;}
  133. else { printf("VALUE OF i is %d : \n",i); P=P->next;}
  134.  
  135. }
  136.  
  137. printf("CIRCULAR LINKED LIST OR COEFICIENT LIST IS CREATED \n ");
  138.  
  139. i=0;P=REF;
  140.  
  141.  
  142. do
  143.  
  144. {
  145. p=0,q=0,r=0,s=0;
  146.  
  147. printf("CALCULATING DET A DET 1 DET 2 \n ");
  148. p=P->a; q=P->next->b; r=P->next->a; s=P->b;
  149.  
  150. detA=p*q - r*s ;
  151.  
  152. printf("DET A is %d : \n ", detA);
  153.  
  154. p=0;q=0;r=0;s=0;
  155.  
  156. p=P->a; q=P->next->k; r=P->next->a; s=P->k;
  157.  
  158. det1=p*q - r*s ;
  159. printf("DET 1 IS %d \n",det1);
  160. p=0;q=0;r=0;s=0;
  161.  
  162. p=P->next->b; q=P->k; r=P->b; s=P->next->k;
  163.  
  164. det2=p*q - r*s ;
  165. printf("DET 2 IS %d \n",det2);
  166.  
  167. printf("Finding the Intersection : \n ");
  168.  
  169. *(x+i)=float(det2)/float(detA);
  170. *(y+i)=float(det1)/float(detA) ;
  171.  
  172. printf("INTERSECTION is : X=%f & Y=%f \n ", *(x+i) , *(y+i) );
  173. i++;
  174. P=P->next;
  175. }
  176. while( P->next->count != 1 ) ;
  177.  
  178. XY=REFPOINT;
  179.  
  180. for(i=0;i<lines;i++)
  181. { XY->x_cord=*(x+i);
  182. XY->y_cord=*(y+i);
  183. XY->count=i;
  184. printf( " X CORD %f Y CORD %f COUNT %d \n ",XY->x_cord,XY->y_cord,XY->count );
  185.  
  186. XY=XY->next;
  187. }
  188.  
  189.  
  190.  
  191.  
  192. XY=REFPOINT;
  193.  
  194. printf("ARE YOU SURE THE LINES IN THE ORDER FORM A REGULAR POLYGON OF %d SIDES : IF SURE ENTER 1 OTHER WISE ENTER 0 :",lines);
  195. scanf("%d",&K);
  196. if(K==1)
  197. {
  198. printf("ENTER THE CORDINATES OF THE POINTS .\n");
  199. printf("ENTER X CORDINATE :");
  200. scanf("%f", &x_cor);
  201. printf("ENTER Y CORDINATE : ");
  202. scanf("%f", &y_cor );
  203. CheckPoint(x_cor,y_cor,XY);
  204. }
  205.  
  206. printf("END \n ");
  207.  
  208. free(x);free(y);free(XY);free(P);
  209. getch();
  210.  
  211. return(0);
  212.  
  213. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.