# Pythagorem theorem

Page 1 of 1

## 3 Replies - 697 Views - Last Post: 22 January 2013 - 11:28 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=308672&amp;s=6b8748d7fb9878beb244ecbf011670f9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 7
• Posts: 236
• Joined: 31-July 09

# Pythagorem theorem

Posted 22 January 2013 - 10:14 AM

hi
having a little problem with pythagorem theorem the problem is is that I've wrote the formula to find the length of the hypotenuse line but when I draw this to the screen the line is longer tha my right triangle help would be appreciated

package trigSystem;

import java.awt.*;
import javax.swing.*;

public class TrigGUI1 extends JFrame
{

/**
*
*/
private static final long serialVersionUID = 1L;

public TrigGUI1()
{
// TODO Auto-generated constructor stub
super();
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

setSize( 500, 500 );
setVisible( true );
}

public void rightTriangle( Graphics g )
{
g.drawLine( 250, 250, 400, 250 );
g.drawLine( 400, 250, 400, 100 );

g.setColor( Color.RED );
g.drawLine( 250, 250, 250 + ( int )pythagoremTheorem(), 250 - ( int )pythagoremTheorem()  );

}
public double pythagoremTheorem()
{
double opp = 150;

double calc = Math.sqrt( hyp );
//System.out.println( "Pythagorem length: " + calc );
return calc;
}

public void paint( Graphics g )
{
super.paint( g );

rightTriangle( g );
}

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
new TrigGUI1();
}

}

I do have an image but having trouble uploading it but will try

This post has been edited by Pin Head: 22 January 2013 - 10:15 AM

Is This A Good Question/Topic? 0

## Replies To: Pythagorem theorem

### #2 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Pythagorem theorem

Posted 22 January 2013 - 10:45 AM

Knowing the hypotenuse would be useful if there was a method that drew a line from a specific point of a certain length in a specific direction. That would look something like:

drawLine( x1, y1, vector );

In your case, you already know x1, y1, and x2, and y2:

x1, y1 = 250, 250
x2, y2 = 400, 100

If you use the x2, y2 in place of the current calculated coordinates for the end of your red line, you'll draw the right line. So, you're not really having a problem with the theorem - your method works fine - but with applying the theorem to a specific problem.

### #3 sk8ermeb

Reputation: 20
• Posts: 133
• Joined: 23-March 10

## Re: Pythagorem theorem

Posted 22 January 2013 - 11:13 AM

This is a Math issue. Greg Brannon's solution will solve it with code. But FYI if you use the hypotenuse to do you diff in X and diff in Y you need to multiply by the cos/sin, respectively, of the angle of the hypotenuse.

### #4 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Pythagorem theorem

Posted 22 January 2013 - 11:28 AM

sk8ermeb, on 22 January 2013 - 01:13 PM, said:

This is a Math issue. Greg Brannon's solution will solve it with code.

Absolutely. I didn't mean to suggest using my "solution" as the final answer, rather as a demonstration that the hypotenuse used in the code's current equation would not arrive at the correct answer. The beginning point + vector = ending point is the more correct approach.

Sorry if I confused.