ProjectLine Program

Determining the lines many functions

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

50 Replies - 2144 Views - Last Post: 29 January 2009 - 09:47 PM Rate Topic: -----

#16 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 08:09 AM

Unless you make a class called point where you have instance variables x and y, you can't return both x and y values from the midpoint method.

You could have something like,

public class Point {
private int px;
private int py;

public Point(int x, int y) {
  px = x;
  py = y;
}

public int getX() {
  return px;
}

public int getY() {
  return py;
}

public Point midpoint(Point p2) {
  // calculate midpoint 
  // return point
}
}


However, since you have the slope and intersections, it could be sufficient (in this case, I'm not saying this is good) to return only the mid-y value from midpoint (or mid-x respectively). Then the other variable could be calculated since it's a linear combination.

This post has been edited by Gloin: 28 January 2009 - 08:12 AM

Was This Post Helpful? 0
  • +
  • -

#17 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 10:31 AM

View PostGloin, on 28 Jan, 2009 - 07:09 AM, said:

Unless you make a class called point where you have instance variables x and y, you can't return both x and y values from the midpoint method.

You could have something like,

public class Point {
private int px;
private int py;

public Point(int x, int y) {
  px = x;
  py = y;
}

public int getX() {
  return px;
}

public int getY() {
  return py;
}

public Point midpoint(Point p2) {
  // calculate midpoint 
  // return point
}
}


However, since you have the slope and intersections, it could be sufficient (in this case, I'm not saying this is good) to return only the mid-y value from midpoint (or mid-x respectively). Then the other variable could be calculated since it's a linear combination.



I understand what you are saying gloin but i am trying to create a simple program to give the out put of the slope of a line when one gives the coordinates, the midpoint, and distance etc.... not a linear algebraically based program.... thanks for the heads up
Was This Post Helpful? 0
  • +
  • -

#18 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 10:40 AM

Yeah, that's what I'm saying.. You could always just put the System.out.println inside the midpoint method and have it print the coordinates from inside there instead of having the method return some value. Just make the method return void.
Was This Post Helpful? 0
  • +
  • -

#19 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 11:20 AM

View PostGloin, on 28 Jan, 2009 - 09:40 AM, said:

Yeah, that's what I'm saying.. You could always just put the System.out.println inside the midpoint method and have it print the coordinates from inside there instead of having the method return some value. Just make the method return void.


You mean like this?

	public double midpoint (double myX1, double myX2, double myY1, double myY2)
	{
		double midpoint = 0;
		midpoint = ((X1+X2)/2 "," (Y1+Y2)/2));
		System.out.println("Your midpoint of the line is" + midpoint);
		return void
	}
	

Was This Post Helpful? 0
  • +
  • -

#20 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 12:03 PM

yeah, you got the idea, but..

public void midpoint (double myX1, double myX2, double myY1, double myY2)
	{
//		double midpoint = 0;
//		midpoint = ((X1+X2)/2 "," (Y1+Y2)/2));
		double midx = (MyX1 + MyX2) * 0.5;
		double midy = (MyY1 + MyY2) * 0.5;
		System.out.println("Your midpoint of the line is" + midx + ":" + midy);
		return;
	}


Was This Post Helpful? 0
  • +
  • -

#21 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 12:05 PM

View PostGloin, on 28 Jan, 2009 - 11:03 AM, said:

yeah, you got the idea, but..

public void midpoint (double myX1, double myX2, double myY1, double myY2)
	{
//		double midpoint = 0;
//		midpoint = ((X1+X2)/2 "," (Y1+Y2)/2));
		double midx = (MyX1 + MyX2) * 0.5;
		double midy = (MyY1 + MyY2) * 0.5;
		System.out.println("Your midpoint of the line is" + midx + ":" + midy);
		return;
	}



Thanks... do you happen to know if the midpoint formula is correct or so? Because at first i was sure but now when i build the file it says that midpoint formula is not a statement

This post has been edited by s.thvlngm: 28 January 2009 - 12:07 PM

Was This Post Helpful? 0
  • +
  • -

#22 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 12:16 PM

Do you wanna know if the formula is correct, then yes..
The method however should likely be declared static as you're not working on any object.

public static void midpoint (double myX1, double myX2, double myY1, double myY2)

This post has been edited by Gloin: 28 January 2009 - 12:17 PM

Was This Post Helpful? 0
  • +
  • -

#23 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 01:33 PM

View PostGloin, on 28 Jan, 2009 - 11:16 AM, said:

Do you wanna know if the formula is correct, then yes..
The method however should likely be declared static as you're not working on any object.

public static void midpoint (double myX1, double myX2, double myY1, double myY2)


Weird... the code makes sense but there are still errrors

')' missing

not a statement

';' expected
Was This Post Helpful? 0
  • +
  • -

#24 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 01:36 PM

If you post the code we can take a look..
Was This Post Helpful? 0
  • +
  • -

#25 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 01:40 PM

View PostGloin, on 28 Jan, 2009 - 12:36 PM, said:

If you post the code we can take a look..



public static void midpoint (double myX1, double myX2, double myY1, double myY2)
	{
		double midpoint = 0;
		midpoint = (((X1+X2)/2)"," (Y1+Y2)/2);
		double midx = (MyX1 + MyX2) * 0.5;
		double midy = (MyY1 + MyY2) * 0.5;
		System.out.println("Your midpoint of the line is" + midx + ":" + midy);
		return;
	}

Was This Post Helpful? 0
  • +
  • -

#26 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 01:42 PM

Remove the two lines that I have commented away.. (or simple comment them away like I did..)

public static void midpoint (double myX1, double myX2, double myY1, double myY2)
{
//		double midpoint = 0;
//		midpoint = (((X1+X2)/2)"," (Y1+Y2)/2);
		double midx = (MyX1 + MyX2) * 0.5;
		double midy = (MyY1 + MyY2) * 0.5;
		System.out.println("Your midpoint of the line is: " + midx + ", " + midy);
		return;
	}	



Edited: I screwed up with the comments..

This post has been edited by Gloin: 28 January 2009 - 01:44 PM

Was This Post Helpful? 0
  • +
  • -

#27 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 02:07 PM

View PostGloin, on 28 Jan, 2009 - 12:42 PM, said:

Remove the two lines that I have commented away.. (or simple comment them away like I did..)

public static void midpoint (double myX1, double myX2, double myY1, double myY2)
{
//		double midpoint = 0;
//		midpoint = (((X1+X2)/2)"," (Y1+Y2)/2);
		double midx = (MyX1 + MyX2) * 0.5;
		double midy = (MyY1 + MyY2) * 0.5;
		System.out.println("Your midpoint of the line is: " + midx + ", " + midy);
		return;
	}	



Edited: I screwed up with the comments..



oh i see... it works.... thanks gloin... and one more question... on my distance formula i don't know if i arranged the math.pow command right could you check if possible


	public double distance (double myX1, double myX2, double myY1, double myY2)
	{
		double distance = 0;
		distance = Math.sqrt(Math.pow(Y2,2) - Math.pow(Y1,2) + 
		Math.pow (X2, 2) - Math.pow(Y2, 2);)
		return distance;
	}
	

Was This Post Helpful? 0
  • +
  • -

#28 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 02:16 PM

It's not quite right..

The distance between two points is calculated using pythagoras theorem.. A^2 + B^2 = C^2 or since you're looking for C, C = SQRT(A^2 + B^2).

In this case A equals the distance between Y1 and Y2, B equals the distance between X1 and X2.
Was This Post Helpful? 0
  • +
  • -

#29 s.thvlngm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-December 08

Re: ProjectLine Program

Posted 28 January 2009 - 02:46 PM

View PostGloin, on 28 Jan, 2009 - 01:16 PM, said:

It's not quite right..

The distance between two points is calculated using pythagoras theorem.. A^2 + B^2 = C^2 or since you're looking for C, C = SQRT(A^2 + B^2).

In this case A equals the distance between Y1 and Y2, B equals the distance between X1 and X2.



correct?

public double distance (double myX1, double myX2, double myY1, double myY2)
	{
		double distance = 0;
		distance = Math.sqrt(Math.pow(Y2,2) - Math.pow(Y1,2) + 
		Math.pow (X2, 2) - Math.pow(Y2, 2) "," Math.sqrt(a^2 + b^2)
		return distance;
	}
	

Was This Post Helpful? 0
  • +
  • -

#30 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: ProjectLine Program

Posted 28 January 2009 - 02:50 PM

No, you have to calculate the differense between the Y-coordinates and then calculate the square of that distance. Do the same for the X-coordinates. Add the two squared distances together and then calculate the squareroot of this sum.

Currently you're calculating the square of the coordinates and then calculating the differense of the squares. See the differense?

This post has been edited by Gloin: 28 January 2009 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4