VB icon

INTERSECTION OF RANDOM TWO LINES FROM A SET OF N LINES

Email
Submitted on: 8/28/2015 5:46:24 AM
By: Mr SHINE KADANATTU AYYAPPAN 
Level: Intermediate
User Rating: Unrated
Compatibility: C, C++ (general)
Views: 89
author picture
 
     I developed a code to find the intersection of two lines that are randomly selected from a set of n lines of General Form Ax+By+C=0 . I created a Linked List for Coefficients of n lines COF .Then read the positions of Two lines Accessed the address of nodes of the two lines from COF P and stored in COF LINE1 and COF LINE2 .then solved for the intersection using DETERMINAT METHOD by Formig 2X2 Matrix ..
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: INTERSECTION OF RANDOM TWO LINES FROM A SET OF N LINES 
// Description:I developed a code to find the intersection of two lines that are randomly selected from a set of n lines of General Form Ax+By+C=0 . I created a Linked List for Coefficients of n lines COF .Then read the positions of Two lines Accessed the address of nodes of the two lines from COF P and stored in COF LINE1 and COF LINE2 .then solved for the intersection using DETERMINAT METHOD by Formig 2X2 Matrix ..
// By: Mr SHINE KADANATTU AYYAPPAN
//**************************************

#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<stdlib.h>
int i=0; 
	int a1=0 , b1=0 ,c1=0;
	int detA =0 , det1 =0 , det2=0 ; int l1=0 ,l2=0;
	float x=0,y=0 ; int lines ;int p=0,q=0,r=0,s=0;
	struct COF {
 int a =0,b=0,c=0;
 int count =0;
 struct COF *next;
	};
	
	COF AccessLine(COF *A,int m)
	{
		 
			do 
			{
				if(A->count==m-1) { return *A; }
			 
			 else { A=A->next ; }
			}
			
			while(A->next->count!=1);
			 
		
		
	}
	
int main(void)
{
	
	struct COF *P;
	P=(COF *) malloc(sizeof(COF));
	struct COF *REF;
	REF=(COF *) malloc(sizeof(COF));
	REF=P;
	
	
	
	printf("Number of lines N= ");
	scanf("%d",&lines);
	
	
for ( i=0;i<lines ; i++ )
	{
	printf("Enter the Coficients of %d thline \n", i+1 );
	printf("Enter a[%d] = ", i);
	scanf("%d",&a1);
	printf("Enter b[%d] = ",i);
	scanf("%d",&b1);
	printf("Enter c[%d] = ",i);
	scanf("%d", &c1);
	P->a=a1; P->b=b1;P->c= -1*c1 ;P->count=i;
	a1=0 ; b1=0 ;c1=0;
	P->next=(COF *) malloc(sizeof(COF));
	if(i==lines-1) { P->next=REF;}
	 else { printf("VALUE OF i is %d : \n",i); P=P->next;}
 
		}	
 printf("CIRCULAR LINKED LIST OR COEFICIENT LIST IS CREATED :PREE ANY LEY ... \n ");
 
 getch();
 printf("ENTER THE LINE NUMBER FOR LINE1 IN BETWEEN 1 AND %d : ",lines);
 scanf("%d",&l1);
 printf("ENTER THE LINE NUMBER FOR LINE2 IN BETWEEN 1 AND %d : ",lines);
 scanf("%d",&l2);
 
 COF *LINE1=(COF *) malloc(sizeof(COF));
 COF *LINE2=(COF *) malloc (sizeof(COF));
 P=REF;
	 *LINE1=AccessLine(P,l1);
	 P=REF;
 *LINE2=AccessLine(P,l2);
 printf("SUCESS .. PRESS ANY KEY ... : \n");getch();
	printf("A line is is%d x + %d y + %d =0 : \n ",LINE1->a,LINE1->b,-1*LINE1->c); 
	printf("A line is is%d x + %d y + %d =0 : \n ",LINE2->a,LINE2->b,-1*LINE2->c); 
		
		printf("CALCULATING INTERSECTION : \n");
		detA= LINE1->a*LINE2->b - LINE1->b*LINE2->a;
		det1=LINE1->a*LINE2->c - LINE2->a*LINE1->c ;
		det2=LINE2->b*LINE1->c - LINE1->b*LINE2->c;
		x=float(det2)/float(detA);
		y=float(det1)/float(detA);
		
		printf("INTERSECTION OF LINES %d & %d IS : X CORD = %f , Y CORD %f :\n",l1,l2,x,y); 
 printf("END OF CODE : PRES ANY KEY ...... : ");
	
	getch();
	
	return(0);
	
	
	
	
}


Other 10 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.