Thread: Homework urgent!

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    5

    Homework urgent!

    How can I coding equation of a line given two points c ++ in functions? Please help!
    Attached Images Attached Images Homework urgent!-ads-z-jpg Homework urgent!-ads-z2-jpg 

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    Quote Originally Posted by cilvegözü View Post
    How can I coding equation of a line given two points c ++ in functions? Please help!
    The instructions say C but you say C++, AND this is a C language forum.

    You need to read the Homework Announcement, along with all the other Announcements at the top of the forum first!

    You also need to make an attempt to code the assignment BEFORE asking for help and advise!

  3. #3
    Registered User
    Join Date
    Nov 2017
    Posts
    5
    Quote Originally Posted by rstanley View Post
    The instructions say C but you say C++, AND this is a C language forum.

    You need to read the Homework Announcement, along with all the other Announcements at the top of the forum first!

    You also need to make an attempt to code the assignment BEFORE asking for help and advise!

    I also made an attemp but I am beginner. So I can't make a functions.
    Last edited by cilvegözü; 12-10-2017 at 09:56 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So post your attempt.

    The polygon seems irrelevant to the problem, since all you're interested in is the boundary.
    So it's really just "is a point" on a list of line segments.

    Figure out the solution to "is a point on a single line segment", which is the essense of the problem.
    If you can do it for one line segment, then doing it for n line segments is easy.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2017
    Posts
    5
    Quote Originally Posted by Salem View Post
    So post your attempt.

    The polygon seems irrelevant to the problem, since all you're interested in is the boundary.
    So it's really just "is a point" on a list of line segments.

    Figure out the solution to "is a point on a single line segment", which is the essense of the problem.
    If you can do it for one line segment, then doing it for n line segments is easy.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    
    
    
    
    
    
    
    int main()
    
    
    
    
    {	int N,counter,counter2;
    	double x,y,a,b;
    	int i,row,column,j;
    		
    	
    	
    	
    	
    	printf("Enter x and y coordinates of the point whose position is investigated:");
    	scanf("%lf%lf",&x,&y);
    	printf("Enter the number of corners for the polygon:");
    	scanf("%d",&N);
    	
    	
    	counter=1;
    	if(N<=2){
    		 counter=0;
    		printf ("The number of corners for creating a polygon is inadequate. ");
    	}
    	
    	
    	while(counter==1){
    
    
    		double A[2][N];
    	
    	
    		for(column=0; column<N; column++){
    			printf("Enter x and y coordinates of the %d.corner :",column);
    				for(row=0;row<2;row++)
    					scanf("%lf",&A[row][column]);	
    				
    		}
    		
    		
    		a=A[0][0];
    		b=A[1][0];
    		for (column=1;column<N;column++){
    			if (A[0][column]==a && A[1][column]==b){
    			
    				printf("The terminal points of the line are same.These inputs do not form a line for the polygon!");
    				counter=0;
    				break;	
    			}
    			else 
    			a=A[0][column];
    			b=A[1][column];	
    		
    		}
    		
    		counter2=0;
    		while (counter2=1){
    		double m,n;
    		for (column=0;column<N;column++){
    			m=(A[1][column+1]-A[1][column])-(A[0][column+1]-A[0][column]);
    			n=A[1][column]/(m*A[0][column]);
    			A[1][column+1]=(m*A[0][column+1])+n;
    			
    						
    			if(y==(m*x)+n ){
    				printf("the point is on the polygon");	
    				counter2=1;
    				break;
    				}
    		}
    		
    		}
    
    
    }
    
    
    
    
    }
    Last edited by cilvegözü; 12-10-2017 at 10:49 AM.

  6. #6
    Registered User
    Join Date
    Nov 2017
    Posts
    5
    Quote Originally Posted by Salem View Post
    So post your attempt.

    The polygon seems irrelevant to the problem, since all you're interested in is the boundary.
    So it's really just "is a point" on a list of line segments.

    Figure out the solution to "is a point on a single line segment", which is the essense of the problem.
    If you can do it for one line segment, then doing it for n line segments is easy.

    How can I do 3.item ?
    Last edited by cilvegözü; 12-10-2017 at 10:50 AM.

  7. #7
    Registered User
    Join Date
    Nov 2017
    Posts
    5
    Quote Originally Posted by rstanley View Post
    The instructions say C but you say C++, AND this is a C language forum.

    You need to read the Homework Announcement, along with all the other Announcements at the top of the forum first!

    You also need to make an attempt to code the assignment BEFORE asking for help and advise!
    How can I do 3.item ?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I mean, create a function.
    Code:
    int isPointOnLine(int px, int py, int x1, int y1, int x2, int y2)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework Help URGENT
    By Thasarathan in forum C Programming
    Replies: 5
    Last Post: 10-15-2017, 08:41 PM
  2. Homework Help URGENT
    By Kamal Joub in forum C Programming
    Replies: 7
    Last Post: 10-12-2017, 05:27 PM
  3. Urgent Help for homework - sum and difference
    By Fatal1ty in forum C++ Programming
    Replies: 3
    Last Post: 03-28-2011, 12:01 PM
  4. need urgent Homework help
    By zakimasmoudi in forum C Programming
    Replies: 2
    Last Post: 11-11-2007, 03:54 PM
  5. Urgent Maths Homework :(
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 01-09-2002, 09:01 PM

Tags for this Thread