Pythagorean theorem

Dear Colleagues
I have recently managed to find the length of the hypotenuse given the lengths of the two opposing sides using sqrt.
I have read that sqrt must be placed after Math because it is part of that class's family.
Just so that I can practice a bit other Math classes, does anybody know which keywords I can use? For instance, how could I use cubic root? Incidentally, why is it Math and not Maths? Isn't it mathematicS?
Use the Pythagorean theorem to find the length
of the hypotenuse given the lengths of the two opposing sides.
class Hypot {
public static void main(String args[]) {
double x, y, z;
x = 3;
y = 4;
z = Math.sqrt(x*x + y*y);
System.out.println("Hypotenuse is " +z);
The output is:
Hypotenuse is 5.0
Cheers!
Steve

As defined:
maths Pronunciation Key (mths)
n. Chiefly British (used with a sing. verb)
Mathematics.
Source: The American Heritage� Dictionary of the English Language, Fourth Edition
Copyright � 2000 by Houghton Mifflin Company.
Published by Houghton Mifflin Company. All rights reserved.
It appears to be a Britishism. Or Unitedism Kingdomism. Or Merry ol' Englandism.
Just having fun everyone. No disrespects to those whom feel slighted. It is much too nice a day to conflict with our neighbors to the East.

Similar Messages

  • Pythagorean triples complex squares

    While working on a math problem recently that involved Pythagorean Triples I spotted a connection with the complex numbers that I had never noticed previously. It is a trivial observation and I was surprised that in my many years as a mathematician I had never heard anyone mention this little fact. I am curious if this little fact is well known to others and I just happened to miss it or if it really is unknown to most folks.
    A Pythagorean triple is a set of three integers like 3,4,5 that make a right triangle with integer sides. Being a right triangle the numbers fit the Pythagorean theorem, a^2 + b^2 = c^2 and sho nuff 9 + 16 = 25
    Euclid has a proof that is presented in the Elements that all Pythagorean triples can be generated from two integers s, and t by means of these formulae
    a = 2st
    b = s^2 - t^2
    c = s^2 + t^2
    It is fairly easy to use algebra to square a and b using those formulae and see that these numbers do in fact form a Pythagorean triple. It is only slightly more difficult to go the other way and show that all triples are of this form.
    So all of this is ancient history - known to Euclid.
    Now let us take a complex number, c = a + bi. Let it be a complex integer, meaning that a and b are actually integers. Viewed from the complex plane, the complex number c represents a little right triangle, one leg is the real part, one leg is the imaginary part and the hypotenuse is the norm of the complex number c i.e.
    |c| = sqrt(a^2 + b^2)
    Clearly because of the square root sign the norm of c is not necessarily an integer and thus the triangle a,b,c is not necessarily a Pythagorean triple. However just square the complex number c
    (a + bi)*(a + bi) = (a^2 - b^2) + (2ab)i
    Notice anything about the form of a perfect square in the complex plane and Euclid's characterization of a Pythagorean triple? One leg is a difference of squares the other is twice the product of the two numbers.
    They are one and the same. The Pythagorean triples are just exactly the perfect squares in the complex plane.
    So for example (2 + i) is not a square and is not a Pythagorean triple. Its norm is sqrt(5). but if you square it, you get (3 + 4i) whose norm is 5.
    That is the observation. Nothing difficult. Perfectly obvious. Every mathematician from Euclid on knows about right triangles and everyone since Gauss has been able to multiply two complex integers. It is about as easy as math gets. I was astonished that in years as a working mathematician I had never noticed this nor heard anyone mention this simple fact.
    Yes, I know - you're thinking that the reason this never came up in conversation is because this observation is totally irrelevant and practically useless, but that has never stopped mathematics. Just ask any mathematician to tell you about paracompact Hausdorff spaces and listen to an amazing tirade of irrelevant and practically useless information.
    The Pythagorean triples are just the perfect squares in the complex plane.
    Just for grins Google 'Pythagorean triples "complex squares"' to see a Google search that returns but a single result. Hole in one. except that it is not about the result that I just mentioned.
    I make no claim that any of this is original, I am only flabbergasted at my ignorance and am casting out to see if I was just asleep the day they covered this in high school or if this really is a rather obscure and little known even if trivial observation.
    There is nothing left to say but to ask the survey questions
    1) Did you know this before you read it here?
    2) If you did know it, was it shown to you or did you discover it yourself?
    Enjoy!

    You are so correct Jos, you can have a common prime root in the legs. Euclid's formula was for the primitive triples.
    I had run into a triple in a problem that I was playing with, remembered that there was a characterization in Euclid and while skimming it noticed that it looked exactly like a squared complex number. This would explain the lack of finding this fact noted on the various math sites - the mere fact that it isn't really true.
    The connection to the complex plane is real but as you say the complex squares are the pirmitive triples not all of them.
    Of course, if I were a good mathematician I would pretend that I knew that all along and in a disgusted tone utter, "Do you take me for some kind of fool? Obviously I meant 'primitive' because it isn't true otherwise."
    These days I am closer to fool than to a good mathematician.
    I am very glad that you pointed this out. The problem I was working on required triples and I was about to limit my considerations to just the primitive ones when in fact a non-primitive one could do.
    Domo arigato gozaimashita!

  • Mouse over a dot

    I have created a component that has small points on it (ellipse with a radius of about 4). This is shown on top of another image and is dynamically generated at runtime.
    My problem is that when I add a mouse listener to the object i need to determine if the mouse is overtop one of the dots, its not very reliable. Its almost as if it does not count all the pixels is passes... so I do not have a chance to determine if the mouse is really overtop of it. Is there a way to optimize that so it really can see every pixel going by... and determine if its moving overtop of it.
    The way I am doing it is determining the distance from the center of the dot to the point in question, then squaring my radius and comparing the result... ( Pythagorean Theorem ). I have this in my mouseMoved function.
    Thanks

    Your explination shows a mathematical error which
    would cause false posatives. squaring the radius
    doesn't tell you much in relation to distances and if
    the point is in the circle. The radius itself is
    what you should be comparing to the distance rather
    than its square.Actually, it's quite common, to avoid a square root computation, to compare r1^2 to r2^2. However, comparing r1 to r2^2 will lead to problems.
    E.g. He said his ellipse (circle) had radius of 4.
    so he should have something like:
    // dotRadiusSq = 16.0;
    double mx = evt.getX();
    double my = evt.getY();
    for each circle (c) {
             double dx = c.x - mx;
             double dy = c.y - my;
             double d = dx * dx + dy * dy;
             if (d <= dotRadiusSq) {
                      // mouse is over circle
    }Another reason to use double / float is if you plan on changing the scale.
    For example, if later you want your program to zoom in, then you'll need to work with double / floats. If you decide to change the shape from a circle to a more complicated shape, then you can just use the shape.contains(...) method.

  • Is my query the very last bit of sql sent through cfquery?

    I have Coldfusion 9 on a Windows Server 2008 box. I have a datasource that points to a Windows Server 2000 with SQL Server 2000. My goal with this template was to determine if my SQL server was recieving any traffic. We anticipate that one or two databases may have select statements being run against it. So, we figured we could use this template to produce proof of activity. (if a process's last query is different from the last one we logged, then that confirms that our sql server is still recieving activity)
    <cfquery name="processes" datasource=#dsn#>
        USE master
        SELECT * from sysprocesses where spid > 50
    </cfquery>
    <cfloop query="processes">
        <cfquery name="lastquery" datasource=#dsn#>
            DBCC INPUTBUFFER(#duckprocesses.spid#)
        </cfquery>
    You can see that I'm using DBCC INPUTBUFFER to determine what the last query was. Utilizing the field called #lastquery.eventinfo# I was hoping to see some queries connected to our datasource. After testing however, I am not getting any proof of my coldfusion server sending sql to my sql server. The queries were successful, because they returned data to my test coldfusion  page, but I couldn't find my query in the inputbuffer command. I know it works, because my sql server queries (run locally on the sql server) returned some results and would properly show up after using the INPUTBUFFER command. However, when I send some queries via <CFQUERY> I do not see the queries in the inputbuffer command.  I do see the following "SET TRANSACTION ISOLATION LEVEL READ COMMITTED" next to the IP address of my Coldfusion server. So that leads me to believe that there is some transactional safety inherit with coldfusion.
    Does coldfusion send ONLY my query to the database server or does it also come inherit with some transactional sql? Like when your CFM throws an error after a <cfquery>INSERT some rows here</cfquery> and the inserted rows do not show up because an error was thrown a few lines down?

    I suggest that you look closely at the MySQL function library reference material for the version of MySQL that you are running ... and, consider upgrading if you need to.
    In any case, you might be able to get more precision by asking for it, e.g. with the CAST() and CONVERT() functions.
    The MySQL documentation (as recently as 5.0) discusses precision math functions.
    Most significantly, though, it seems that MySQL now offers a library of geo-spatial (GIS) functions which might make it possible for you to go well beyond the Pythagorean Theorem in addressing your problem.  The boundaries of each ZIP Code are, of course, a closed polygon, and what you are really looking for here is to determine containment of a chosen point within this and/or adjacent polygons.  MySQL 5.0, for instance, appears to have considerable direct support for this.  You do have to purchase these data sets.
    See:  http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html

  • New iMac Display Sizes

    I'm ready to buy one of the new iMac models but when looking at the current 20", 24" monitors, I think the 24" is the largest I can comfortable accommodate on my desk.
    I note that the newly released iMac is available as a 21.5" or a 27" in a 16:9 ratio. What was the old ratio, or better yet, is the viewable screen size of a new 27" the same as the old 24" or is it larger?
    If the new sizes equal the viewable sizes of the old iMac screens then I can accommodate a 27" model on my desk. If it is larger, I'll have to get a 21.5".
    Thanks
    kayjh

    Again, the important thing is pixel count. A 50-inch HDTV may have a physically larger display, but it only has 1920x1080 pixels (the same as the 21.5-inch new iMac). Larger pixels does not let you do more with your computer, MORE pixels does.
    You can figure out the pixel density this way. Using the [Pythagorean theorem|http://en.wikipedia.org/wiki/Pythagorean_theorem],
    !http://upload.wikimedia.org/math/1/4/5/1455314a78f39a594485adbaf74d63f9.png!
    figure out how many pixels go along th diagonal. You know a (2560) and b (1440), so you can figure out c. I get 2937 pixels along the diagonal. That diagonal is 27 inches, so the pixel density (pixels per inch) is 2937 divided by 27, or about 109 ppi.
    For the 24-inch display, using the same math, it is only about 94 ppi.
    So objects on the new display will look about 10% smaller than they would look on the old display. The new display will also look more sharp for the same reason. And as I mentioned above, the new display has 60% more pixels to work with compared to the old display.

  • Do theories need to be single tests?

    Looking at the turnkey project theory tests, I see that no matter how many combinations are tried for a given theory there's only one result shown for the whole series of tests.
    I'd been hoping to use theories to construct data-driven tests, but have one test per datapoint reported. For instance, I'd have a "theory" that my code should be able to import any given input file and not throw errors. Then I'd put the theory to the test over a large set of files and get individual test results for each file in the set.
    Is this stretching the theory idea too far? Or should I be able to make a runner that would do this the way I want (creating unique test IDs for each data point, running through the entire data set if errors are encountered, etc.).

    Alan,
    Short answer: Yes, that is stretching the idea somewhere it isn't supposed to go.
    When you think of a theory, think mathematical theory.
    Any combination of values that disprove a theory, means they theory itself is false, not that a particular set of values is a failure.
    So, in FlexUnit/JUnit, a theory is about trying something that is supposed to be true over a potentially infinite set of data, and verifying that it always true for that data set. If there was any combination of numbers that made the pythagorean theorem false, then the entire theorem is disproved.
    That said, what you are looking for is parameterized testing. That is something that we have infrastructure already built for inside of FlexUnit 4, but have not built it all the way to the test case level. This feature will likely make it in before we have a release version, but (before anyone asks) I don't have a timeline on that just yet.
    Mike

  • In inches, how high is the part of the screen actually usable?

    In inches, how high is the part of the screen actually usable for text or images?... on the new iMac Apple computer models.
    In inches, how wide is the part of the screen actually usable for text or images?...
    Message was edited by: dsaklad@ zurich.csail.mit.edu

    You use [Pythagorean theorem|http://en.wikipedia.org/wiki/Pythagorean_theorem]
    !http://upload.wikimedia.org/math/1/4/5/1455314a78f39a594485adbaf74d63f9.png!
    to calculate how many pixels would go along the diagonal, C in the equation. You know A and B from the resolution numbers.
    Divide that pixel number (C from above) by the diagonal measurement in inches to get the +pixels per inch+ number (PPI).
    Divide the horizontal and vertical resolution numbers by the PPI number, to get the measurements in inches.

  • Want to mass-delete an object

    I have a 700 page document that has thick rule objects I wish to mass-delete. I am putting them on master pages for consistency and to isolate them to their own layer. The ones I wish to delete are all locked, but are inconsistently positioned.
    The Find/Change dialog provides for finding objects that meet certain criteria, but I see no option to DELETE the found object, just to CHANGE it. I realize there is a certain amount of danger in such an option, but If I were to change the objects to some unique color before subsequently searching on that color and deleting them all, that would be a kind of safety step.
    As a safer alternative to deleting the objects automatically, I would like the option to move these found objects to their own layer, so that I could just delete the entire layer after reviewing what was placed there.
    Can this kind of mass deletion or mass movement to another layer be done?

    OK, here you go—it appears to be necessary to calculate the length with the Pythagorean theorem (distance formula), since InDesign just returns the corners of the bounding box surrounding the stroke.
    Also, for convenience, the commented-out lines print out some information about each rule that is operated on -- you might uncomment them and comment out the .remove() if you want to see what it is going to do first.
    var
        i,
        doc = app.activeDocument,
        rules = doc.graphicLines,
        bounds, length, x, y, g;
    for (i=rules.length-1; i>=0; i--) {
        g = rules[i].geometricBounds;
        x = g[3]-g[1];
        y = g[2]-g[0];
        length = Math.sqrt(x*x+y*y);
        if (rules[i].strokeWeight >= 2 && length > 4) {
            // $.writeln("Found rule "+i+" x "+x+" y "+y+" length "+
            // length+" weight "+rules[i].strokeWeight);
            rules[i].remove();
    strokeWeight appears to give the apparent stroke weight, regardless of whether it was initially set or if the rule was scaled to get there.

  • Which is worse: awkwardly long or vague/arbitrary variable names?

    I'm programming in C++, but that shouldn't matter.
    I'm working on a small chunk of code that is a module for a much, much larger project. Part of my code is to make several hundred histograms and then run some statistics over them.
    My dilemma is that there are so many, that naming them is becoming difficult. So, I opt for incredibly long, cumbersome names rather than short arbitrary names. Heck, even I wouldn't know what was going on if I just named them "histo1, histo2." Instead I name them things like "MomentumTimesDeltaPhiEta1" which MIGHT make sense to someone who is working on another part of the project.
    And actually, that wasn't a real example. Some of my names are longer than that. Is that normal? I have programmed in C++ for a year, but I'm still not good at programming etiquette, so my code looks clumsy.

    Local vars can be short, if you find the need to give further explanation, comment. Try to give meaningful names more for class atributes, interfaces, and where a variable name can help documenting the code itself. E.g. (Pseudo-code, as I don't remeber a lot of C++):
    Instead of:
    z = sqr(a^2 + b^2)
    This is better:
    // Pythagorean theorem
    z = sqr(a^2 + b^2)
    This is even better:
    hypotenuse = sqr(catheti_a^2 + catheti_b^2)
    If you find yourself using incredible long variable names, it's a signal that your program is too flat, and you need to start refactoring it into a function, class, or using a namespace.
    So, e.g:
    namespace Geometry {
    function Hypotenuse(float a, b) {
    return sqr(a^2 + b^2)
    The code expresses a lot more meaning, while staying concise.
    Edit: I forgot square root
    Last edited by freakcode (2008-08-06 19:49:58)

  • Camera Field of View

    What is the field of view (degrees) for the Iphone camera, and other popular camera phones?
    Thanks

    For the iPhone - the CCD detector is a rectangular chip. So, the long axis (i.e. the 'width' if you hold the iPhone in landscape mode) has a ~53° viewing angle. The short axis (i.e. the 'width if you hold the iPhone in portrait mode) has a viewing angle of ~37.5°. Can't speak for other camera phones.
    A nice exercise with a ruler, and thanks for making me dredge my memory for the Pythagorean theorem and the formula to solve an isosceles triangle!
    Tbo6652, how'd you come up with 45°?

  • Pythagoras Theorem Triplets

    What is the formula for finding Pythagorean integer triples?
    For ex: 3 4 5 is a triplet. How do I find the next triplet?

    Check out http://mathworld.wolfram.com/PythagoreanTriple.html, and then think about whether this is the right place to answer this question....

  • Need help to develop Pythagoras theorem-

    Hi i need help to develop proofs 2,3,4
    of pythagoras theorems in java as demonstrations
    These are applets can anyone help me with it or give me an idea of how to go about developing it -
    the site is the following
    http://www.uni-koeln.de/ew-fak/Mathe/Projekte/VisuPro/pythagoras/pythagoras.html
    then double click on the screen to make it start

    Pardon my ASCII art, but I've always liked the following, simple, geometric proof:
         a                   b
    ---------------------------------------+
    |       |                                |
    a|   I   |              II                |
    |       |                                |
    ---------------------------------------+
    |       |                                |
    |       |                                |
    |       |                                |
    |       |                                |
    |       |                                |
    b|  IV   |              III               |
    |       |                                |
    |       |                                |
    |       |                                |
    |       |                                |
    |       |                                |
    |       |                                |
    ---------------------------------------+It almost goes without saying that I+II+III+IV == (a+b)^2, and II == IV == a*b,
    I == a*a and III == b*b, showing that (a+b)^2 == a^2+a*b+a*b+b^2.
    I hope the following sketch makes sense, stand back, ASCII art alert again:     a                   b
    ---------------------------------------+
    |               .             VI         |
    |     .                 .                |a
    | V                               .      |
    |                                        +
    |                                        |
    |   .                                    |
    b|                                     .  |
    |                                        |
    |                  IX                    |
    | .                                      |
    |                                    .   |b
    |                                        |
    +                                        |
    |      .                                 |
    a|               .                  . VII |
    |  VIII                   .              |
    ---------------------------------------+
                     a                    bThe total area equals (a+b)^2 again and equals the sum of the smaller areas:
    (a+b)^2 == V+VI+VII+VIII+IX. Let area IX be c^2 for whatever c may be.
    V+VII == VI+VIII == a*b, so a^2+b^2+2*ab= c^2+2*a*b; IOW a^2+b^2 == c^2
    Given this fundamental result, the others can easily be derived from this one,
    or did I answer a question you didn't ask?
    kind regards,
    Jos

  • PYTHAGORAS THEOREM __ URGENT HELP  NEEDED

    Hi everyone - I am developing various proofs of the pythagora's theorem
    and the following code draws a triangle on screen and the proof follows -
    but i need to know how to drag the triangle such tht 1 angle is always set to 90 degrees.
    i.e. i need to resize the triangle by dragging its vertex points by which the1 angle remains at 90 no matter what the size.
    The proof has got some graphics code hardcoded in it - i.e. LINES AND POLYGONS have been hardcoded
    i need to reconfigure that such that everytime the user increases the size of the triagnle and clicks on next it draws the lines and polygons in the correct area and place
    PLEASE HELP
    the code is as follows
    MAIN CLASS
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;
    public class TestProof {
        TestControl control;          // the controls for the visual proof
        TestView view;          // the drawing area to display proof
        // called upon class creation
        public TestProof() {
            view = new TestView();
    view.setBackground(Color.WHITE);
            control = new TestControl(view);
            Frame f = new Frame("Pythagoras");
            f.add(view,"Center");
            f.add(control,"South");
            f.setSize(600,600);
            f.setBackground(Color.lightGray);
            f.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
       File.add(Exit);
            f.add(menuBar,"North");
            f.show();
        private JMenuBar getMenuBar() {
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
                 File.add(Exit);   
            return menuBar;
        private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        // for standalone use
        public static void main(String args[]) {
      TestProof TP = new TestProof();
    }Test VIEW
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestView extends Canvas {
        int TRANSLUCENT = 1;
        int sequence;          // sequencer that determines what should be drawn
        // notes matter
        int noteX = 100;     // note coordinates
        int noteY = 60;
        int fontSize = 11;     // font size
        int lineSpacing     // space between two consecutive lines
        = fontSize + 2;
        Font noteFaceFont;     // font used to display notes
        // objects matter
        Polygon tri;          // right-angled triangle with sides A, B, and C
        Polygon tri1;
        Polygon sqrA;          // square with side of length A
        Polygon sqrB;          // square with side of length B
        Polygon sqrC;          // square with side of length C
        Polygon parA;          // parallelogram of base A and height A
        Polygon parB;          // parallelogram of base B and height B
        Polygon poly1;
        Polygon poly2;
        Polygon poly3;
        Polygon poly4;
        Polygon poly5;
        Polygon poly6;
        int X0 = 350;          // coordinates of triangle
        int Y0 = 350;
        int A = 90;//60;          // triangle size
        int B = 120;//80;
        int C = 150;//100;
        //CORDS of 2nd triangle
        int X1 = 350;
        int Y1 = 500;
        // notes: three lines per note
        String notes[] = {
            // note 0
            // note 1
            // note 2
            // note 3
            // note 4
            // note 5
            // note 6
            // note 7
            // note 8
            // note 9
            // note 10
            // note 11
            // note 12
            // note 13
            // note 14
        // constructor
        public TestView() {
            addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            // set font
            noteFaceFont = new Font("TimesRoman", Font.PLAIN, fontSize);
            // (coordinates specified w.r.t. to P0, unless otherwise specified)
            // create the triangle
            tri = new Polygon();
            tri.addPoint(0, 0);                    // add P0 coordinate
            tri.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            tri.addPoint(C, 0);                    // add C1 coordinate
            tri.translate(X0, Y0);               // place triangle
            tri1 = new Polygon();
            tri1.addPoint(0,0);                    // add P0 coordinate
            tri1.addPoint(A*A/C +38, +A*B/C);          // add A3 coordinate
            tri1.addPoint(C, 0);                    // add C1 coordinate
            tri1.translate(X1, Y1);
            // create square of side A
            sqrA = new Polygon();
            sqrA.addPoint(0, 0);               // add P0 coordinate
            sqrA.addPoint(-A*B/C, -A*A/C);          // add A1 coordinate
            sqrA.addPoint(-A*(B-A)/C, -A*(A+B)/C);     // add A2 coordinate
            sqrA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            sqrA.translate(X0, Y0);               // place square
            // create square of side B
            // warning: the coordinate of this object are specified relative to C1
            sqrB = new Polygon();
            sqrB.addPoint(0, 0);               // add C1 coordinate
            sqrB.addPoint(B*A/C, -B*B/C);          // add B1 coordinate
            sqrB.addPoint(B*(A-B)/C, -B*(A+B)/C);     // add B2 coordinate
            sqrB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            sqrB.translate(X0 + C, Y0);               // place square
            // create square of side C
            sqrC = new Polygon();
            sqrC.addPoint(0, 0);               // add P0 coordinate
            sqrC.addPoint(C, 0);               // add C1 coordinate
            sqrC.addPoint(C, C);               // add C2 coordinate
            sqrC.addPoint(0, C);               // add C3 coordinate
            sqrC.translate(X0, Y0);               // place square
            poly1 = new Polygon();
            poly1.addPoint(405,279);
            poly1.addPoint(413,350);
            poly1.addPoint(432,500);
            poly1.addPoint(442,571);
            poly1.addPoint(500,500);
            poly1.addPoint(500,350);
            poly2 = new Polygon();
            poly2.addPoint(279,297);
            poly2.addPoint(404,280);
            poly2.addPoint(571,254);
            poly2.addPoint(500,350);
            poly2.addPoint(350,350);
            //Polygon 3
            poly3 = new Polygon();
            poly3.addPoint(404,280);
            poly3.addPoint(350,350);
            poly3.addPoint(414,350);
            poly4 = new Polygon();
            poly4.addPoint(350,350);
            poly4.addPoint(350,500);
            poly4.addPoint(442,572);
            poly4.addPoint(433,500);
            poly4.addPoint(414,350);
            poly5 = new Polygon();
            poly5.addPoint(476,183);
            poly5.addPoint(332,225);
            poly5.addPoint(278,295);
            poly5.addPoint(404,279);
            poly5.addPoint(571,254);
            poly6= new Polygon();
            poly6.addPoint(405,278);
            poly6.addPoint(332,224);
            poly6.addPoint(476,182);
            // create parallelogram of height A
            parA = new Polygon();
            parA.addPoint(0, 0);               // add P0 coordinate
            parA.addPoint(0, C);               // add C3 coordinate
            parA.addPoint(A*A/C, C - A*B/C);          // add Q0 coordinate
            parA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            parA.translate(X0,Y0);               // place parallelogram
            // create parallelogram of height B
            // warning: the coordinate of this object are specified from C1
            parB = new Polygon();
            parB.addPoint(0, 0);               // add C1 coordinate
            parB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            parB.addPoint(A*A/C - C, C - A*B/C);     // add Q0 coordinate
            parB.addPoint(0, C);               // add C2 coordinate
            parB.translate(X0 + C, Y0);
            // place parallelogram
        // depending on the sequence number we draw certain objects
        public void paint(Graphics gfx) {
            super.paint(gfx);
            Graphics2D g = (Graphics2D) gfx;
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
            // text first, then objects (and animation)
            // we always output some notes
            g.drawString(notes[3*sequence], noteX, noteY);
            g.drawString(notes[3*sequence + 1], noteX, noteY + lineSpacing);
            g.drawString(notes[3*sequence + 2], noteX, noteY + 2*lineSpacing);
            // the object are drawn in an order so that they are properly overlapped
            if(sequence == 13) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.RED);
                g.setColor(Color.GREEN);
                g.drawLine(413,351,433,499);
                g.setColor(Color.white);
                g.fillPolygon(tri);
                g.fillPolygon(tri1);
                g.fillPolygon(poly6);
            if(sequence == 12 ) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.BLACK);
            if(sequence == 11){
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.setColor(Color.BLACK);
            if(sequence == 8 ){
                g.setColor(Color.green);
                g.fillPolygon(poly5);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            else if (sequence == 9 ){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if( sequence == 10){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.fillPolygon(poly5);
                g.setColor(Color.black);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if(sequence == 7){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
            if(sequence == 6){
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.green);
                g.fillPolygon(poly3);
                g.setColor(Color.blue);
                g.fillPolygon(poly4);
                g.setColor(Color.black);
                g.drawArc(250,175,350,275,300,65);
                //g.drawArc(250,150,350,250,320,65);
                g.drawLine( 606,309,599,299);
                g.drawLine(592,313, 599,299);
                g.drawString("+90 degrees",605,378);
            if (sequence == 5 ) {
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.black);
            if (sequence == 4) {
                g.setColor(Color.YELLOW);
                g.fillPolygon(poly1);
                g.setColor(Color.black);
                g.drawArc(319,310,250,195,89,-35);
                g.drawLine(499,319, 492,312);
                g.drawLine(499,319, 492,325);
                g.drawArc(200,180, 233,238,-120,-60);
                g.drawLine(200,298, 208,309);
                g.drawLine(200,298, 194,313);
                g.drawString("-90 degrees",227,347);
            if (sequence >= 3) {
                g.drawLine(404,279,442,572);
            // draw the squares
            if (sequence >= 2) {
                g.drawLine(278,296,572,254);
            // draw the squares
            if (sequence >= 1) {
                g.drawLine(333,224,476,182);
                g.drawPolygon(tri1);
            // always draw the triangle
            g.drawPolygon(tri);
            g.drawPolygon(sqrA);
            g.drawPolygon(sqrB);
            g.drawPolygon(sqrC);
            g.setColor(Color.MAGENTA);
            g.drawString("C", X0 + C/2 - fontSize/2, Y0 + lineSpacing);
            g.drawString("A",
            X0 + A*A/(2*C) - fontSize*A/B/2,
            Y0 - A*B/(2*C) - lineSpacing*A/B);
            g.drawString("B",
            X0 + C - B*B/(2*C) - fontSize*A/B/2,// the last "-" isn't log.
            Y0 - B*A/(2*C) - lineSpacing*A/B);
        public void redraw(int sequence) {
            this.sequence = sequence;
            repaint();
    }TEST CONTROL
    * TestControl.java
    * Created on 28 February 2005, 11:16
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.JFrame;
    * @author  Kripa Bhojwani
    public class TestControl extends Panel implements ActionListener {
      TestView view;
      int sequence;                    // event sequence
      // constructor
      public TestControl(TestView view) {
        Button b = null;
        Label label = new Label("A^2 ");
        this.view = view;          // initialize drawble area
        sequence = 0;               // initialize sequence
        b = new Button("Prev");
        b.addActionListener(this);
        add(b);
        b = new Button("Next");
        b.addActionListener(this);
        add(b);
        add(label);
      // exported method
      public void actionPerformed(ActionEvent ev) {
        String label = ev.getActionCommand();
        if (label.equals("Prev")) {
          if (sequence >0) {
         --sequence;
        else {
          if (sequence < 15) {
         ++sequence;
        this.setEnabled(false);          // disable the controls
        view.redraw(sequence);
        this.setEnabled(true);          // enable the controls
    }Please help --- really need to sort this out...
    THANKS

    Can any one help me with this --
    basically need to draw a triangle with BC as the Base and the HYPOTENUSE of a right angle triangle right angled at A...
    [    code]
    A
    B/-----------------------------/C
    So angle A should be 90 degrees
    and the user should be able to Drag sides B and C anywhere on screen
    PLEASE HELP

  • PYTHAGORAS THEOREM ) HELP NEEDED

    Hi everyone - I am developing various proofs of the pythagora's theorem
    and the following code draws a triangle on screen and the proof follows -
    but i need to know how to drag the triangle such tht 1 angle is always set to 90 degrees.
    i.e. i need to resize the triangle by dragging its vertex points by which the1 angle remains at 90 no matter what the size.
    The proof has got some graphics code hardcoded in it - i.e. LINES AND POLYGONS have been hardcoded
    i need to reconfigure that such that everytime the user increases the size of the triagnle and clicks on next it draws the lines and polygons in the correct area and place
    PLEASE HELP
    the code is as follows
    MAIN CLASS
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;
    public class TestProof {
        TestControl control;          // the controls for the visual proof
        TestView view;          // the drawing area to display proof
        // called upon class creation
        public TestProof() {
            view = new TestView();
    view.setBackground(Color.WHITE);
            control = new TestControl(view);
            Frame f = new Frame("Pythagoras");
            f.add(view,"Center");
            f.add(control,"South");
            f.setSize(600,600);
            f.setBackground(Color.lightGray);
            f.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
       File.add(Exit);
            f.add(menuBar,"North");
            f.show();
        private JMenuBar getMenuBar() {
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
                 File.add(Exit);   
            return menuBar;
        private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        // for standalone use
        public static void main(String args[]) {
      TestProof TP = new TestProof();
    }Test VIEW
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestView extends Canvas {
        int TRANSLUCENT = 1;
        int sequence;          // sequencer that determines what should be drawn
        // notes matter
        int noteX = 100;     // note coordinates
        int noteY = 60;
        int fontSize = 11;     // font size
        int lineSpacing     // space between two consecutive lines
        = fontSize + 2;
        Font noteFaceFont;     // font used to display notes
        // objects matter
        Polygon tri;          // right-angled triangle with sides A, B, and C
        Polygon tri1;
        Polygon sqrA;          // square with side of length A
        Polygon sqrB;          // square with side of length B
        Polygon sqrC;          // square with side of length C
        Polygon parA;          // parallelogram of base A and height A
        Polygon parB;          // parallelogram of base B and height B
        Polygon poly1;
        Polygon poly2;
        Polygon poly3;
        Polygon poly4;
        Polygon poly5;
        Polygon poly6;
        int X0 = 350;          // coordinates of triangle
        int Y0 = 350;
        int A = 90;//60;          // triangle size
        int B = 120;//80;
        int C = 150;//100;
        //CORDS of 2nd triangle
        int X1 = 350;
        int Y1 = 500;
        // notes: three lines per note
        String notes[] = {
            // note 0
            // note 1
            // note 2
            // note 3
            // note 4
            // note 5
            // note 6
            // note 7
            // note 8
            // note 9
            // note 10
            // note 11
            // note 12
            // note 13
            // note 14
        // constructor
        public TestView() {
            addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            // set font
            noteFaceFont = new Font("TimesRoman", Font.PLAIN, fontSize);
            // (coordinates specified w.r.t. to P0, unless otherwise specified)
            // create the triangle
            tri = new Polygon();
            tri.addPoint(0, 0);                    // add P0 coordinate
            tri.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            tri.addPoint(C, 0);                    // add C1 coordinate
            tri.translate(X0, Y0);               // place triangle
            tri1 = new Polygon();
            tri1.addPoint(0,0);                    // add P0 coordinate
            tri1.addPoint(A*A/C +38, +A*B/C);          // add A3 coordinate
            tri1.addPoint(C, 0);                    // add C1 coordinate
            tri1.translate(X1, Y1);
            // create square of side A
            sqrA = new Polygon();
            sqrA.addPoint(0, 0);               // add P0 coordinate
            sqrA.addPoint(-A*B/C, -A*A/C);          // add A1 coordinate
            sqrA.addPoint(-A*(B-A)/C, -A*(A+B)/C);     // add A2 coordinate
            sqrA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            sqrA.translate(X0, Y0);               // place square
            // create square of side B
            // warning: the coordinate of this object are specified relative to C1
            sqrB = new Polygon();
            sqrB.addPoint(0, 0);               // add C1 coordinate
            sqrB.addPoint(B*A/C, -B*B/C);          // add B1 coordinate
            sqrB.addPoint(B*(A-B)/C, -B*(A+B)/C);     // add B2 coordinate
            sqrB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            sqrB.translate(X0 + C, Y0);               // place square
            // create square of side C
            sqrC = new Polygon();
            sqrC.addPoint(0, 0);               // add P0 coordinate
            sqrC.addPoint(C, 0);               // add C1 coordinate
            sqrC.addPoint(C, C);               // add C2 coordinate
            sqrC.addPoint(0, C);               // add C3 coordinate
            sqrC.translate(X0, Y0);               // place square
            poly1 = new Polygon();
            poly1.addPoint(405,279);
            poly1.addPoint(413,350);
            poly1.addPoint(432,500);
            poly1.addPoint(442,571);
            poly1.addPoint(500,500);
            poly1.addPoint(500,350);
            poly2 = new Polygon();
            poly2.addPoint(279,297);
            poly2.addPoint(404,280);
            poly2.addPoint(571,254);
            poly2.addPoint(500,350);
            poly2.addPoint(350,350);
            //Polygon 3
            poly3 = new Polygon();
            poly3.addPoint(404,280);
            poly3.addPoint(350,350);
            poly3.addPoint(414,350);
            poly4 = new Polygon();
            poly4.addPoint(350,350);
            poly4.addPoint(350,500);
            poly4.addPoint(442,572);
            poly4.addPoint(433,500);
            poly4.addPoint(414,350);
            poly5 = new Polygon();
            poly5.addPoint(476,183);
            poly5.addPoint(332,225);
            poly5.addPoint(278,295);
            poly5.addPoint(404,279);
            poly5.addPoint(571,254);
            poly6= new Polygon();
            poly6.addPoint(405,278);
            poly6.addPoint(332,224);
            poly6.addPoint(476,182);
            // create parallelogram of height A
            parA = new Polygon();
            parA.addPoint(0, 0);               // add P0 coordinate
            parA.addPoint(0, C);               // add C3 coordinate
            parA.addPoint(A*A/C, C - A*B/C);          // add Q0 coordinate
            parA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            parA.translate(X0,Y0);               // place parallelogram
            // create parallelogram of height B
            // warning: the coordinate of this object are specified from C1
            parB = new Polygon();
            parB.addPoint(0, 0);               // add C1 coordinate
            parB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            parB.addPoint(A*A/C - C, C - A*B/C);     // add Q0 coordinate
            parB.addPoint(0, C);               // add C2 coordinate
            parB.translate(X0 + C, Y0);
            // place parallelogram
        // depending on the sequence number we draw certain objects
        public void paint(Graphics gfx) {
            super.paint(gfx);
            Graphics2D g = (Graphics2D) gfx;
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
            // text first, then objects (and animation)
            // we always output some notes
            g.drawString(notes[3*sequence], noteX, noteY);
            g.drawString(notes[3*sequence + 1], noteX, noteY + lineSpacing);
            g.drawString(notes[3*sequence + 2], noteX, noteY + 2*lineSpacing);
            // the object are drawn in an order so that they are properly overlapped
            if(sequence == 13) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.RED);
                g.setColor(Color.GREEN);
                g.drawLine(413,351,433,499);
                g.setColor(Color.white);
                g.fillPolygon(tri);
                g.fillPolygon(tri1);
                g.fillPolygon(poly6);
            if(sequence == 12 ) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.BLACK);
            if(sequence == 11){
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.setColor(Color.BLACK);
            if(sequence == 8 ){
                g.setColor(Color.green);
                g.fillPolygon(poly5);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            else if (sequence == 9 ){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if( sequence == 10){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.fillPolygon(poly5);
                g.setColor(Color.black);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if(sequence == 7){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
            if(sequence == 6){
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.green);
                g.fillPolygon(poly3);
                g.setColor(Color.blue);
                g.fillPolygon(poly4);
                g.setColor(Color.black);
                g.drawArc(250,175,350,275,300,65);
                //g.drawArc(250,150,350,250,320,65);
                g.drawLine( 606,309,599,299);
                g.drawLine(592,313, 599,299);
                g.drawString("+90 degrees",605,378);
            if (sequence == 5 ) {
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.black);
            if (sequence == 4) {
                g.setColor(Color.YELLOW);
                g.fillPolygon(poly1);
                g.setColor(Color.black);
                g.drawArc(319,310,250,195,89,-35);
                g.drawLine(499,319, 492,312);
                g.drawLine(499,319, 492,325);
                g.drawArc(200,180, 233,238,-120,-60);
                g.drawLine(200,298, 208,309);
                g.drawLine(200,298, 194,313);
                g.drawString("-90 degrees",227,347);
            if (sequence >= 3) {
                g.drawLine(404,279,442,572);
            // draw the squares
            if (sequence >= 2) {
                g.drawLine(278,296,572,254);
            // draw the squares
            if (sequence >= 1) {
                g.drawLine(333,224,476,182);
                g.drawPolygon(tri1);
            // always draw the triangle
            g.drawPolygon(tri);
            g.drawPolygon(sqrA);
            g.drawPolygon(sqrB);
            g.drawPolygon(sqrC);
            g.setColor(Color.MAGENTA);
            g.drawString("C", X0 + C/2 - fontSize/2, Y0 + lineSpacing);
            g.drawString("A",
            X0 + A*A/(2*C) - fontSize*A/B/2,
            Y0 - A*B/(2*C) - lineSpacing*A/B);
            g.drawString("B",
            X0 + C - B*B/(2*C) - fontSize*A/B/2,// the last "-" isn't log.
            Y0 - B*A/(2*C) - lineSpacing*A/B);
        public void redraw(int sequence) {
            this.sequence = sequence;
            repaint();
    }TEST CONTROL
    * TestControl.java
    * Created on 28 February 2005, 11:16
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.JFrame;
    * @author  Kripa Bhojwani
    public class TestControl extends Panel implements ActionListener {
      TestView view;
      int sequence;                    // event sequence
      // constructor
      public TestControl(TestView view) {
        Button b = null;
        Label label = new Label("A^2 ");
        this.view = view;          // initialize drawble area
        sequence = 0;               // initialize sequence
        b = new Button("Prev");
        b.addActionListener(this);
        add(b);
        b = new Button("Next");
        b.addActionListener(this);
        add(b);
        add(label);
      // exported method
      public void actionPerformed(ActionEvent ev) {
        String label = ev.getActionCommand();
        if (label.equals("Prev")) {
          if (sequence >0) {
         --sequence;
        else {
          if (sequence < 15) {
         ++sequence;
        this.setEnabled(false);          // disable the controls
        view.redraw(sequence);
        this.setEnabled(true);          // enable the controls
    }Please help --- really need to sort this out...
    THANKS

    Cross post http://forum.java.sun.com/thread.jspa?threadID=603432&messageID=3251958#3251958

  • PYTHAGORAS THEOREM

    I need to know if anyone has coded the pythagoras theorem using areas of squares to prove the theorem.
    I have got a triangle on screen with my angles and side lengths displayed in a jtable. I need to extend it to display the sides as squares.
    such that the ares of the side and the base = area of the square from the hypotenuse..
    PLEASE REPLY SOON

    such that the ares of the side and the base = area of
    the square from the hypotenuse..You only have to display the square of the three sides. Pythagoras will personally take care of the theorem for you from his small study in Math Heaven.

Maybe you are looking for