1. A PROGRAM THAT PROVIDES THE INTERSECTION COORDINATES OF TWO LINES GIVEN THE COORDINATES OF LINE A AND LINE B.
2. A PROGRAM THAT WILL BE ABLE TO CALCULATE THE GRADIENT/SLOPE OF A LINE GIVEN TWO POINTS.
i want to know what i am doing to do, how to even start it i have no ideas can u pls explain to me how to go about it
NB:
i learn best by doing so i will be glad if u can add example codes to it
8 replies to this topic
#1
Posted 15 May 2011 - 11:56 PM
|
|
|
#2
Posted 16 May 2011 - 02:36 AM
Study your theory! In the first question you'll just have to find the functions for line A and line B, say the coordinates for line A are : (x11,y11),(x12,y12)...imagine the first point being somewehre left and down on the cartesian coordinate system and the second righter and upperer :P
(...all you need to define a line is either two points or one point and the line's angle...) then its angle would be a=(y12-y11)/(x12-x11) so its function would be f(x)=ax, the function for line B would look like g(x)=y1-bx (the B line would lean to the left...)...i think it's enough hint
(...all you need to define a line is either two points or one point and the line's angle...) then its angle would be a=(y12-y11)/(x12-x11) so its function would be f(x)=ax, the function for line B would look like g(x)=y1-bx (the B line would lean to the left...)...i think it's enough hint
#3
Posted 16 May 2011 - 03:26 AM
And for 2:

Where m is the slope.

Where m is the slope.
#4
Posted 19 May 2011 - 01:04 PM
wim DC said:
And for 2:

Where m is the slope.

Where m is the slope.
i am trying to put the coordinates of y into an array but it is not working can u correct this for me i do not want to create classes for this program
import javax.swing.JOptionPane;
/**
*
* @author irvan
*/
public class Main {
// private static Object Cord_y;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double Codr_x[];
double Codr_y[];
Codr_y = new double[2];
Codr_x = new double [2];
int z =1;
for (int i = 0; i < Cord_y.length(); i++) {
String in = JOptionPane.showInputDialog("Enter the coordinates for Y"+z);
Cord_y =Double.parseDouble(in);
++z;
#5
Posted 19 May 2011 - 01:06 PM
thanks for the formula
now i am trying to put the coordinates of y into an array but it is not working can u correct this for me i do not want to create classes for this program
now i am trying to put the coordinates of y into an array but it is not working can u correct this for me i do not want to create classes for this program
import javax.swing.JOptionPane;
/**
*
* @author irvan
*/
public class Main {
// private static Object Cord_y;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double Codr_x[];
double Codr_y[];
Codr_y = new double[2];
Codr_x = new double [2];
int z =1;
for (int i = 0; i < Cord_y.length(); i++) {
String in = JOptionPane.showInputDialog("Enter the coordinates for Y"+z);
Cord_y =Double.parseDouble(in);
++z;
#6
Posted 19 May 2011 - 11:10 PM
Edit: Mr Mike got it in other thread.
#7
Posted 20 May 2011 - 01:55 AM
i want the code to be edited for me. and the JOptionPane.showInputDialog is my headache now
i tried mr.mike's correction but the same problem can u do something about it for me.
this is the code with mr.mike's correction u can ran it and see for urself
i tried mr.mike's correction but the same problem can u do something about it for me.
this is the code with mr.mike's correction u can ran it and see for urself
import javax.swing.JOptionPane;
public class lindemontry1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double Codr_x[];
double Codr_y[];
Codr_y = new double[2];
Codr_x = new double [2];
int z =1;
for (int i = 0; i < Cord_y.length(); i++) {
String in = JOptionPane.showInputDialog("Enter the coordinates for Y"+z);
Cord_y[i] =Double.parseDouble(in);
++z;
}
}
Edited by atoivan, 20 May 2011 - 02:36 AM.
#8
Posted 20 May 2011 - 02:22 AM
Bat0u89 said:
Study your theory! In the first question you'll just have to find the functions for line A and line B, say the coordinates for line A are : (x11,y11),(x12,y12)...imagine the first point being somewehre left and down on the cartesian coordinate system and the second righter and upperer :P
(...all you need to define a line is either two points or one point and the line's angle...) then its angle would be a=(y12-y11)/(x12-x11) so its function would be f(x)=ax, the function for line B would look like g(x)=y1-bx (the B line would lean to the left...)...i think it's enough hint
(...all you need to define a line is either two points or one point and the line's angle...) then its angle would be a=(y12-y11)/(x12-x11) so its function would be f(x)=ax, the function for line B would look like g(x)=y1-bx (the B line would lean to the left...)...i think it's enough hint
thank for the hint i wrote the program i want to know i have done the right thing :
import java.util.Scanner;
public class Linedemo2 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
double x1=0,x2=0,x3=0,x4=0,x=0,y=0,y1=0,y2=0,y3=0,y4=0;
System.out.println("ENTER THE TWO PIONTS FOR LINE A");
x1 =in.nextDouble();
y1 =in.nextDouble();
x2 =in.nextDouble();
y2 =in.nextDouble();
System.out.println("ENTER THE TWO PIONTS FOR LINE B");
x3 =in.nextDouble();
y3 =in.nextDouble();
x4 =in.nextDouble();
y4 =in.nextDouble();
double m1,m2,c1,c2;
m1=(y1-y2)/(x1-x2);//Gradient for line 1
m2=(y3-y4)/(x3-x4);//gradient for line 2
c1=y1-(m1*x1); // the y intercept for line 1
c2=y3-(m2*x3); //the y intercept for line 2
x=(c1-c2)/(m1-m2);
y=(m1*x1)-c1;
System.out.println("THE TWO LINE MEET AT POINT(mid-point)" + x + y );
}
}
#9
Posted 21 May 2011 - 12:47 AM
Quote
m1=(y1-y2)/(x1-x2);//Gradient for line 1
m2=(y3-y4)/(x3-x4);//gradient for line 2
c1=y1-(m1*x1); // the y intercept for line 1
c2=y3-(m2*x3); //the y intercept for line 2
x=(c1-c2)/(m1-m2);
y=(m1*x1)-c1;
System.out.println("THE TWO LINE MEET AT POINT(mid-point)" + x + y );
m2=(y3-y4)/(x3-x4);//gradient for line 2
c1=y1-(m1*x1); // the y intercept for line 1
c2=y3-(m2*x3); //the y intercept for line 2
x=(c1-c2)/(m1-m2);
y=(m1*x1)-c1;
System.out.println("THE TWO LINE MEET AT POINT(mid-point)" + x + y );
m1=(y2-y1)/(x2-x1);//Gradient for line 1
m2=(y3-y4)/(x4-x3);//gradient for line 2
//basically it would look better to get the
//absolute value of each subtraction here...
//Now I show you how to find the x coordinate of the intersection point
//then you can find the y coordinate by m1*x (the function for line 1) OR
// y3-m2*x
//This is simple algebra:
//m1*x=y3-m2*x <=>
//m1*x+m2*x=y3 <=>
//x(m1+m2)=y1 <=>
//x=y1/(m1+m2)
//put all this to code...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









