Intersection of Random Two Lines From a Set of N Lines

Language

This project will teach you how to get intersection of random two lines from a set of N lines. It was created using C/C++. This is very easy to do project. Download the 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.  
  6. int i=0;
  7. int a1=0 , b1=0 ,c1=0;
  8. int detA =0 , det1 =0 , det2=0 ; int l1=0 ,l2=0;
  9. float x=0,y=0 ; int lines ;int p=0,q=0,r=0,s=0;
  10. struct COF {
  11. int a =0,b=0,c=0,k=0;
  12. int count =0;
  13. struct COF *next;
  14. };
  15.  
  16. COF AccessLine(COF *A,int m)
  17. {
  18.  
  19. do
  20. {
  21. if(A->count==m-1) { return *A; }
  22.  
  23. else { A=A->next ; }
  24. }
  25.  
  26. while(A->next->count!=1);
  27.  
  28.  
  29.  
  30. }
  31.  
  32. int main(void)
  33.  
  34. {
  35.  
  36.  
  37. struct COF *P;
  38. P=(COF *) malloc(sizeof(COF));
  39. struct COF *REF;
  40. REF=(COF *) malloc(sizeof(COF));
  41. REF=P;
  42.  
  43.  
  44.  
  45. printf("Number of lines N= ");
  46. scanf("%d",&lines);
  47.  
  48.  
  49.  
  50. for ( i=0;i<lines ; i++ )
  51.  
  52. {
  53. printf("Enter the Coficients of %d th line \n", i+1 );
  54. printf("Enter a[%d] = ", i);
  55. scanf("%d",&a1);
  56. printf("Enter b[%d] = ",i);
  57. scanf("%d",&b1);
  58. printf("Enter c[%d] = ",i);
  59. scanf("%d", &c1);
  60. P->a=a1; P->b=b1;P->c=c1 ;P->k=-1*c1;P->count=i;
  61. a1=0 ; b1=0 ;c1=0;
  62. P->next=(COF *) malloc(sizeof(COF));
  63. if(i==lines-1) { P->next=REF;}
  64. else { printf("VALUE OF i is %d : \n",i); P=P->next;}
  65.  
  66. }
  67.  
  68. printf("CIRCULAR LINKED LIST OR COEFICIENT LIST IS CREATED :PREE ANY LEY ... \n ");
  69.  
  70. getch();
  71. printf("ENTER THE LINE NUMBER FOR LINE1 IN BETWEEN 1 AND %d : ",lines);
  72. scanf("%d",&l1);
  73. printf("ENTER THE LINE NUMBER FOR LINE2 IN BETWEEN 1 AND %d : ",lines);
  74. scanf("%d",&l2);
  75.  
  76. COF *LINE1=(COF *) malloc(sizeof(COF));
  77. COF *LINE2=(COF *) malloc (sizeof(COF));
  78. P=REF;
  79. *LINE1=AccessLine(P,l1);
  80. P=REF;
  81. *LINE2=AccessLine(P,l2);
  82. printf("SUCESS .. PRESS ANY KEY ... : \n");getch();
  83. printf("A line is is %d x + %d y + %d =0 : \n ",LINE1->a,LINE1->b,LINE1->c);
  84. printf("A line is is %d x + %d y + %d =0 : \n ",LINE2->a,LINE2->b,LINE2->c);
  85.  
  86. printf("CALCULATING INTERSECTION : \n");
  87. detA= LINE1->a*LINE2->b - LINE1->b*LINE2->a;
  88. det1=LINE1->a*LINE2->k - LINE2->a*LINE1->k ;
  89. det2=LINE2->b*LINE1->k - LINE1->b*LINE2->k;
  90. x=float(det2)/float(detA);
  91. y=float(det1)/float(detA);
  92.  
  93. printf("INTERSECTION OF LINES %d & %d IS : X CORD = %f , Y CORD %f :\n",l1,l2,x,y);
  94. printf("END OF CODE : PRES ANY KEY ...... : ");
  95.  
  96. getch();
  97.  
  98. return(0);
  99. }

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