DeMorgan's Theorem

I couldn't find anything on google that explained DeMorgan''s Theorem clearly enough. Can someone tell me what it is and how it is used in java. Any explaination or links are good.

if (! (q == null || q.isEmpty())) {
}is logically equivalent to:
if (q != null && ! q.isEmpty()) {
}Moreover, even if your expression has side effects, the two statements still evaluate the same way...

Similar Messages

  • 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.

  • Want a .vi program for verification of superposition theorem.......

    Hi...everyone
    Please anyone can post me the .vi program for verification of superposition theorem for a resistive circuit. I am using labview 8.5.1 on windows xp platform.
    I have a circuit on the NI-ELVIS prototyping board  and that i have to interface to the Labview. At least tell me how i can proceed for making this front panel...
    plzzzz its urgent
    Thank you....... 

    This appears to be a homework problem. If the above link does not answer your question(s) then please post back with specific questions. We will not do your homework for you, but we can provide hints.

  • Determining spectral density of poisson process (carson theorem)

    Has anyone ever determined code for working out the spectral density (or
    equivalent) of a Poisson process, based on Carson theorem (or a variant
    thereof)? It doesn't have to be in Labview, but that would be the easiest (or VB).Message Edited by Jo on 05-01-2005 11:34 PM

  • How to integrate RFSG driver with sampling theorem labview code

    hi all, 
    I got the labview code of sampling theorem from labview-> find examples. How can I integrate this code with PXI system? How can I integrate the RFSG driver with labview code?

    Hi Nieman,
    LabVIEW 2014 should be compatible with the 9068 and the cRIO 2.1 drivers.  I verified it should work as expected earlier today.  Please make sure you are using the example cRIO PN-IO Device when you are moving the module over to the new target.  If you are already accessing that, please navigate to this folder:
    <Program Files>\National Instruments\LabVIEW 2014\Targets\NI\FPGA\cRIO\other
    Please let me know if you see a CS_cRIO-PNAD folder. This folder provides all the files necessary to discover and use the module in the project.  If we do not have that folder there, we will be unable to locate the module.  If that is indeed the case, then it may be the driver did not install correctly.  
    If after finding this folder and it is still not working, please send me screenshots of the error that you are seeing and a MAX Technical Report.  Thanks!
    Matt S.
    Industrial Communications Product Support Engineer
    National Instruments

  • Signal Conditioning and Shannon Theorem

    Hi, 
    I need to acquire a signal and then to condition it. I am planning on using the SCX-1102 which has a lowpass filter (2Hz).
    I would like to know if this lowpass filter has to respect the shannon theorem and has to be > 2*fmax.
    In my case.. the fmax of my signal is 1.5Hz.
    Thank you! 

    Hello,
    I assume you are referring to the Nyquist-Shannon sampling theorem that states that the sampling frequency must be at least twice the frequency of the signal.  This applies to sampling, not low pass filters.  Just make sure you sample at a high enough rate (more than twice, 10x is better, the expected frequency of your signal - including all frequency content, even frequencies that you would like to filter out), and then the filter will eliminate frequencies above 2 Hz.  
    - Christina

  • Collisions (Separating Axis Theorem)

    Hi,
    I'm working on a 2D game, it's top-down like GTA2, but I'm havinfgproblems with the collision detector. I know there are a lot of posts about collision already but they didn't help me much. I'm using the separating axis theorem (explained here: http://www.harveycartel.org/metanet/tutorials/tutorialA.html#section1) and most of the code is inspired by http://www.codeproject.com/cs/media/PolygonCollision.asp .
    Separating axis theorem:
    find all axis perpendicular to all the edges of both objects,
    project both objects on the axis,
    if there is an axis where the projections do not overlap, then the objects do not overlap.
    The problem is that I think my code should work. And guess what, it doesn't. I checked the code 30 times this weekend but maybe there is some tiny mistake I overlook each time..
    When I run the program with 6 objects I get this:
    1 2 3 4 5 6
    1: - 0 0 0 0 0
    2: 0 - 1 0 0 0
    3: 0 1 - 0 0 0
    4: 0 0 0 - 0 0
    5: 0 0 0 0 - 0
    6: 0 0 0 0 0 - (1=intersect, 0=doesn't intersect)
    but this is completely wrong. You can run the program yourself to see the exact locations of the objects.
    1 is the triangle at the top,
    2 and 3 are the triangles who share an edge
    4 is the one on the left intersecting with 3
    5 is the triangle on the right
    6 is the parallelogram
    But it really gets weird when I add a 7th object (the one in the comments):
    1 2 3 4 5 6 7
    1: - 0 0 0 0 0 0
    2: 0 - 0 0 0 0 0
    3: 0 0 - 0 0 0 0
    4: 0 0 0 - 0 0 0
    5: 0 0 0 0 - 0 0
    6: 0 0 0 0 0 - 0
    7: 0 0 0 0 0 0 -
    Now 2 and 3 don't intersect anymore! They didn't change I just added another object.
    I'm adding a short explanationof all the classes and the code itself. I know it's a lot of code but I added all the test classes so you can just run Test.Test
    I hope someone can help me with this.
    Thanks,
    El Bandano
    _<h5>package CollisionDetector:</h5>_
    <h6>CollisionDetector</h6>
    The class that is supposed to check for collisions. It will take 2 Props and return a CollisionResult
    <h6>CollisionResult</h6>
    A small class with 2 public fields. For now only the boolean Intersect matters.
    <h6>Interval</h6>
    Another small class that represents an interval of floats. It's pretty simple. Distance should return something negative if 2 intervals overlap.
    _<h5>package World</h5>_
    <h6>MovableProp</h6>
    An interface of an object. All objects should be convex.
    <h6>Vector2D</h6>
    A 2D-vector. It has an x and a y value (floats) and some simple methods. a 2D vector can represent a point or an edge/axis. For a point the x and y are the coordinates. For an axis you need a normalized vector (x^2+y^2=1) and the x and y are coordinates on a parrallell line through (0,0).
    _<h5>package Test</h5>_
    <h6>Test</h6>
    The main class. It makes some objects, prints a matrix showin which intersect eachother and shows a window with all objects.
    <h6>TestMovProp</h6>
    A basic implementation of MovableProp.
    <h6>TestPanel</h6>
    A panel that draws MovableProp.
    _<h5>package CollisionDetector:</h5>_
    <h6>CollisionDetector</h6>
    package CollsisionDetector;
    import World.MovableProp;
    import World.Vector2D;
    import java.util.ArrayList;
    public class CollisionDetector {
        public CollisionDetector(){
        public CollisionResult DetectCollision(MovableProp propA, MovableProp propB) {
            CollisionResult result = new CollisionResult();
            result.Intersect = true;
            result.WillIntersect = true;
            Vector2D[] edges = UniqueEdges(propA, propB);
            // loop through the edges
            // find an axis perpendicular to the edge
            // project the props on the axis
            // check wether they intersect on that axis
            for (Vector2D edge: edges){
                Vector2D axis = edge.getPerpendicular();
                Interval intA = projectPointsOnAxis(propA.getCoordinates(), axis);
                Interval intB = projectPointsOnAxis(propB.getCoordinates(), axis);
                if (intA.distance(intB) > 0)
                    result.Intersect = false;
            return result;
        public Interval projectPointsOnAxis(Vector2D[] points, Vector2D axis){
            Interval i = new Interval();
            for (Vector2D p: points)
                i.add(projectPointOnAxis(p, axis));
            return i;
        public float projectPointOnAxis(Vector2D point, Vector2D axis){
            // axis <-> y=a*x
            float a  = axis.y / axis.x;
            // line <-> y=(-a/1)*x+b
            float a2 = -axis.x / axis.y;
            // b = y-a2*x
            float b = point.y - a2*point.x;
            // y = a *x
            // y = a2*x + b
            // => a*x = a2*x + b
            float x = b/(a-a2);
            float y = a*x;
            // is there a better way to do this?
            return new Float(Math.sqrt(x*x + y*y)).floatValue();
         * Put all edges in 1 array, eliminate doubles (parallels).
        public Vector2D[] UniqueEdges(MovableProp propA,MovableProp propB){
            Vector2D[] aEdges = propA.getEdges();
            Vector2D[] bEdges = propB.getEdges();
            ArrayList<Vector2D> tmp = new ArrayList<Vector2D>();
            for (Vector2D v: aEdges){
                tmp.add(v);
            for (Vector2D v: bEdges){
               if (! tmp.contains(v))
                    tmp.add(v);
            return tmp.toArray(new Vector2D[tmp.size()]);
    }<h6>CollisionResult</h6>
    package CollsisionDetector;
    import World.Vector2D;
    public class CollisionResult {
        public boolean WillIntersect;
        public boolean Intersect;
        public Vector2D MinimumTranslationVector;
        public CollisionResult() {
    }<h6>Interval</h6>
    package CollsisionDetector;
    public class Interval {
        public float min;
        public float max;
        public Interval() {
            min = Float.MAX_VALUE;
            max = Float.MIN_VALUE;
        public void add(float f){
            // no 'else'! In an empty interval both will be true
            if (f>max)
                max = f;
            if (f<min)
                min = f;
        public float distance(Interval interval){
            if (this.min < interval.min) {
                return interval.min - this.min;
            } else {
                return this.min - interval.min;
    }_<h5>package World</h5>_
    <h6>MovableProp</h6>
    package World;
    public interface MovableProp {
        public int getNPoints();
        public Vector2D[] getEdges();
        public Vector2D[] getCoordinates();
    }<h6>Vector2D</h6>
    package World;
    public class Vector2D {
        public float x;
        public float y;
        public Vector2D(float x, float y) {
            this.x = x;
            this.y = y;
        public boolean equals(Object obj){
            if (!(obj instanceof Vector2D)){
                return false;
            }else
                return (this.x == ((Vector2D)obj).x && this.y == ((Vector2D)obj).y);
        public String toString() {
            return ("Vector2D  x=" + x + " ,  y=" + y);
        public void normalize(){
            if (x*x + y*y != 1){
                float x2 = x;
                x /= Math.sqrt(x2*x2+y*y);
                y /= Math.sqrt(x2*x2+y*y);
        public Vector2D getPerpendicular(){
            Vector2D per = new Vector2D(-y,x);
            per.normalize();
            return per;
    }_<h5>package Test</h5>_
    <h6>Test</h6>
    package Test;
    import CollsisionDetector.CollisionDetector;
    import World.MovableProp;
    import java.awt.Polygon;
    import java.util.ArrayList;
    import java.util.Vector;
    import javax.swing.JFrame;
    public class Test {
        public static void main(String args[]) {
            CollisionDetector detect = new CollisionDetector();
            float[] x = new float[3];
            float[] y = new float[3];
            ArrayList<MovableProp> list = new ArrayList<MovableProp>();
            x[0] = 200; x[1] = 300; x[2] = 500;
            y[0] = 400; y[1] = 200; y[2] = 300;
            list.add(new TestMovProp(x,y));
            x[0] = 300; x[1] = 500; x[2] = 600;
            y[0] = 400; y[1] = 400; y[2] = 500;
            list.add(new TestMovProp(x,y));
            x[0] = 200; x[1] = 300; x[2] = 600;
            y[0] = 600; y[1] = 400; y[2] = 500;
            list.add(new TestMovProp(x,y));
            x[0] = 100; x[1] = 200; x[2] = 300;
            y[0] = 800; y[1] = 500; y[2] = 700;
            list.add(new TestMovProp(x,y));
            x[0] = 600; x[1] = 600; x[2] = 700;
            y[0] = 400; y[1] = 700; y[2] = 500;
            list.add(new TestMovProp(x,y));
    //        x[0] = 100; x[1] = 001; x[2] = 900;
    //        y[0] = 001; y[1] = 900; y[2] = 500;
    //        list.add(new TestMovProp(x,y));
            x = new float[4];
            y = new float[4];
            x[0] = 450; x[1] = 550; x[2] = 500; x[3] = 400;
            y[0] = 200; y[1] = 250; y[2] = 650; y[3] = 600;
            list.add(new TestMovProp(x,y));
            int n = list.size();
            boolean[][] matrix = new boolean[n][n];
            for (int i=0; i<n; i++){
                for (int j=0; j<n; j++){
                    if (i!=j)
                    matrix[i][j] = detect.DetectCollision(list.get(i),list.get(j)).Intersect;
            System.out.print("  ");
            for (int i=0; i<n; i++){
                System.out.print("  " + (i+1));
            for (int i=0; i<n; i++){
                System.out.print("\n" + (i+1) + ":  ");
                for (int j=0; j<n; j++){
                    if (i==j)
                        System.out.print("-  ");
                    else if (matrix[i][j])
                        System.out.print("1  ");
                    else
                        System.out.print("0  ");
            System.out.println();
            JFrame window = new JFrame();
            window.setDefaultCloseOperation(window.EXIT_ON_CLOSE);
            window.pack();
            window.setVisible(true);
            window.setContentPane( new TestPanel(list));
            window.pack();
    }<h6>TestMovProp</h6>
    package Test;
    import World.MovableProp;
    import World.Vector2D;
    public class TestMovProp implements MovableProp{
        float[] X;
        float[] Y;
        Vector2D[] coor;
        public TestMovProp(float[] x, float[] y) {
            X=x; Y=y;
            coor = new Vector2D[getNPoints()];
            for(int i=0; i< getNPoints(); i++){
                coor[i] = new Vector2D(X, Y[i]);
    public Vector2D[] getCoordinates(){
    return coor;
    public int getNPoints() {
    return X.length;
    public Vector2D[] getEdges() {
    int n = getNPoints();
    Vector2D[] v = new Vector2D[n];
    for (int i=0; i<n-1; i++){
    v[i] = new Vector2D(X[i]-X[i+1], Y[i]-Y[i+1]);
    v[i].normalize();
    v[n-1] = new Vector2D(X[0]-X[n-1], Y[0]-Y[n-1]);
    v[n-1].normalize();
    return v;
    public String toString() {
    String s = "\n";
    for (Vector2D v: getCoordinates())
    s += ("\n" + v);
    return s;
    <h6>TestPanel</h6>package Test;
    import World.MovableProp;
    import World.Vector2D;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Polygon;
    import java.util.ArrayList;
    import javax.swing.JPanel;
    public class TestPanel extends JPanel {
    public ArrayList<MovableProp> list;
    public TestPanel(ArrayList<MovableProp> list) {
    super();
    this.list = list;
    setPreferredSize(new Dimension(1000,850));
    public void paint(Graphics g) {
    super.paint(g);
    for (MovableProp prop:list){
    Vector2D[] coor = prop.getCoordinates();
    int n = prop.getNPoints();
    g.drawLine((int)coor[0].x, (int)coor[0].y, (int)coor[n-1].x, (int)coor[n-1].y);
    for (int i=0; i<n-1; i++){
    g.drawLine((int)coor[i].x, (int)coor[i].y, (int)coor[i+1].x, (int)coor[i+1].y);

    .java wrote:
    I have been search for what seems like hours, Nice try, but in less than 15 seconds I found a complete discussion on the subject.
    and I still have not managed to find anybody or anything that can clearly answer these three questions:
    1. What is SAT?
    2. How does it apply to 2D collision detection? (How would it be different with 3D collision detection?)
    3. How can this be implemented in Java using Shape objects?
    Note: I am easily confused by geometric terminology.This really looks like a question you should have an answer for in your notes from class, or in your book. If not perhaps you need to go ask your teacher what it is and explain why you don't have it in your notes or book.

  • Triangle Intercept Theorem -

    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Dimension;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class G {
        CardLayout cards;
        JPanel panel;
        public G() {
            cards = new CardLayout();
            panel = new JPanel(cards);
            addCards();
            JFrame f = new JFrame("Geometry");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(panel);
            Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            f.setSize(screenSize);
            f.setLocation(0,0);
            f.setVisible(true);
            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());
        private void addCards() {
            // card THREE
            //{211,100},{124,150},{298,150}}, new int[][] {{422,200},{248,300},{596,300}
            InterceptModel trin1 = new InterceptModel(new int[][] {{300,100},{250,146},{594,146}}, new int[][] {{300,100},{138,300},{440,300}});
            InterceptView view1  = new InterceptView(trin1);
            JPanel panelThree = new JPanel(new BorderLayout());
            panelThree.add(view1.getUIPanel(), "North");
            // panelTwo.setBackground(Color.blue);
            panelThree.setName("Intercept Theorem");
            panelThree.add(view1);
            //panelThree.add(view1.getInterceptTablePanelA(), "East");
            //JPanel rightPanel1 = new JPanel();
            //rightPanel1.add(view1.getTxtPanel());
            //panelThree.add(rightPanel1, "South");
            panelThree.add(view1.getInterceptTablePanel(),"South");
            view1.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse at " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Dragging: x=" + e.getX() + "; y=" + e.getY());
            panel.add("Intercept Theorem", panelThree);
           private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        public static void main(String[] args) {
            new G();
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    * @author  Sharan Bhojwani
    public class InterceptModel {
                                                      //      |\
        static final int SIDES = 3;                //      | \
        private int cx, cy;                        //      |  \
        Polygon smallTriangle;
        Polygon bigTriangle;                       //      |_ _\ (x3, y3)
        int selectedIndex;                         //  (x2, y2)
        NumberFormat nf;
        Line2D[] medians;
        Point2D centroid;
        // The ratio of scaling, NOT size
        // i.e. the ratio of scaling can be 2 and yet the triangles the same size
        int ratio;
        /** Creates a new instance of InterceptModel */
        public InterceptModel(int[][] triangleOne, int[][] triangleTwo)
            // make first triangle
            int[] x = new int[] { triangleOne[0][0], triangleOne[1][0], triangleOne[2][0] };
            int[] y = new int[] {triangleOne[0][1], triangleOne[1][1], triangleOne[2][1] };
            smallTriangle = new Polygon(x, y, SIDES);
            // make second triangle
            int[] x2 = new int[] { triangleTwo[0][0], triangleTwo[1][0], triangleTwo[2][0] };
            int[] y2 = new int[] {triangleTwo[0][1], triangleTwo[1][1], triangleTwo[2][1] };
            bigTriangle = new Polygon(x2,y2,SIDES);
            nf = NumberFormat.getNumberInstance();
            nf.setMaximumFractionDigits(1);
            ratio=3;
        public void setRatio(int ratio) {
            this.ratio = ratio;
            sizeTriangles();
        public int getRatio() {
            return ratio;
        // this sets the size of the triangles once the ratio has been changed
        // ratio is side of smaller triangle AB in 100's of pixels
        void sizeTriangles() {
            //work out x & y ratios
            int xleftSmall = (int) (ratio*100 * Math.sin(30));
            int yleftSmall = (int) (ratio*100 * Math.cos(30));
            int yrightSmall = yleftSmall;
            int xrightSmall = (int) (yleftSmall * Math.tan(40));
            int xSmall[] = {300,300-xleftSmall,300+xrightSmall};
            int ySmall[] = {100,100+yleftSmall,100+yrightSmall};
            smallTriangle.xpoints = xSmall;
            smallTriangle.ypoints = ySmall;
            int bigRatio = ratio*100*2;
            //work out x & y ratios
            int xleftBig = (int) (bigRatio * Math.sin(30));
            int yleftBig = (int) (bigRatio * Math.cos(30));
            int yrightBig = yleftBig;
            int xrightBig = (int) (yleftBig * Math.tan(40));
            int xBig[] = {300,300-xleftBig,300+xrightBig};
            int yBig[] = {100,100+yleftBig,100+yrightBig};
            bigTriangle.xpoints = xBig;
            bigTriangle.ypoints = yBig;
            System.out.println("changed sizes");
           // take x0,y0 of big
           int[] x = (int[]) bigTriangle.xpoints.clone();
           int[] y = (int[]) bigTriangle.ypoints.clone();
           // bring bigTriangle points to 0,0 to make things easier
           for (int i=SIDES-1; i>-1; i--) {
               x[i] = x[i] - x[0];
               y[i] = y[i] - y[0];
           // resize to make small triangle points
           for (int i=0; i<SIDES; i++) {
               x[i] = x[i] / ratio;
               y[i] = y[i] / ratio;
           // translate to fit onto the pane
           for (int i=0; i<SIDES; i++) {
               x[i] = x[i] + 213;
               y[i] = y[i] + 125;
           smallTriangle.xpoints = x;
           smallTriangle.ypoints = y;
            public boolean contains(Point p, Polygon triangle)
            // Polygon.contains doesn't work well enough
            return (new Area(triangle)).contains(p);
        public boolean isLineSelected(Rectangle r)
            Line2D line = new Line2D.Double();
            for(int j = 0; j < SIDES; j++)
                int[] x = smallTriangle.xpoints;
                int[] y = smallTriangle.ypoints;
                int x1 = x[j];
                int y1 = y[j];
                int x2 = x[(j + 1) % SIDES];
                int y2 = y[(j + 1) % SIDES];
                line.setLine(x1, y1, x2, y2);
                if(line.intersects(r))
                    selectedIndex = j;
                    return true;
            selectedIndex = -1;
            return false;
        public void moveSide(int dx, int dy, Point p)
            int[] x = smallTriangle.xpoints;
            int[] y = smallTriangle.ypoints;
            int[] x1 = bigTriangle.xpoints;
            int[] y1 = bigTriangle.ypoints;
            switch(selectedIndex)
                case 0:
                    double length =  Math.sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]));
                    int xpoint = x[1] + dx;
                    int ypoint = y[1] + dy;
                    double newlength = Math.sqrt((xpoint-x[0])*(xpoint-x[0]) + (ypoint-y[0])*(ypoint-y[0]));
                    double scale = length/newlength;
                    x[1] = new Double(p.x*scale).intValue();
                    y[1] = new Double(p.y*scale).intValue();
                    int px_forBig = ((p.x - x[0])*ratio) + x1[0];
                    int py_forBig = ((p.y - y[0])*ratio) + y1[0];
                    x1[1] = new Double( px_forBig  * scale).intValue();
                    y1[1] = new Double( py_forBig  * scale).intValue();
                    break;
                case 1:
                    length =  Math.sqrt((x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]));
                    xpoint = x[2] + dx;
                    ypoint = y[2] + dy;
                    newlength = Math.sqrt((xpoint-x[1])*(xpoint-x[1]) + (ypoint-y[1])*(ypoint-y[1]));
                    scale = length/newlength;
                    x[2] = new Double(p.x*scale).intValue();
                    y[2] = new Double(p.y*scale).intValue();
                    px_forBig = ((p.x - x[1])*ratio) + x1[1];
                    py_forBig = ((p.y - y[1])*ratio) + y1[1];
                    x1[2] = new Double( px_forBig  * scale).intValue();
                    y1[2] = new Double( py_forBig  * scale).intValue();
                    break;
                case 2:
      length =  Math.sqrt((x[0]-x[2])*(x[0]-x[2]) + (y[0]-y[2])*(y[0]-y[2]));
                    xpoint = x[0] + dx;
                    ypoint = y[0] + dy;
                    newlength = Math.sqrt((xpoint-x[2])*(xpoint-x[2]) + (ypoint-y[2])*(ypoint-y[2]));
                    scale = length/newlength;
                    x[0] = new Double(p.x*scale).intValue();
                    y[0] = new Double(p.y*scale).intValue();
                    px_forBig = ((p.x - x[2])*ratio) + x1[2];
                    py_forBig = ((p.y - y[2])*ratio) + y1[2];
                    x1[0] = new Double( px_forBig  * scale).intValue();
                    y1[0] = new Double( py_forBig  * scale).intValue();
        public void translate(int dx, int dy, Polygon triangle)
            triangle.translate(dx, dy);
        public Polygon getSmallTriangle()
            return smallTriangle;
        public Polygon getBigTriangle()
            return bigTriangle;
        public String findCentroid(Polygon triangle)
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            // construct the medians defined as the line from
            // any vertex to the midpoint of the opposite line
            medians = new Line2D[x.length];
            for(int j = 0; j < x.length; j++)
                int next = (j + 1) % x.length;
                int last = (j + 2) % x.length;
                Point2D vertex = new Point2D.Double(x[j], y[j]);
                // get midpoint of line opposite vertex
                double dx = ((double)x[last] - x[next])/2;
                double dy = ((double)y[last] - y[next])/2;
                Point2D oppLineCenter = new Point2D.Double(x[next] + dx,
                                                           y[next] + dy);
                medians[j] = new Line2D.Double(vertex, oppLineCenter);
            // centroid is located on any median 2/3 the way from the
            // vertex (P1) to the midpoint (P2) on the opposite side
            double[] lengths = getSideLengths(triangle);
            double dx = (medians[0].getX2() - medians[0].getX1())*2/3;
            double dy = (medians[0].getY2() - medians[0].getY1())*2/3;
            double px = medians[0].getX1() + dx;
            double py = medians[0].getY1() + dy;
            //System.out.println("px = " + nf.format(px) +
            //                 "\tpy = " + nf.format(py));
            centroid = new Point2D.Double(px, py);
            return "(" + nf.format(px) + ",  " + nf.format(py) + ")";
        public String[] getAngles(Polygon triangle)
            double[] lengths = getSideLengths(triangle);
            String[] vertices = new String[lengths.length];
            for(int j = 0; j < lengths.length; j++)
                int opp  = (j + 1) % lengths.length;
                int last = (j + 2) % lengths.length;
                double top = lengths[j] * lengths[j] +
                             lengths[last] * lengths[last] -
                             lengths[opp] * lengths[opp];
                double divisor = 2 * lengths[j] * lengths[last];
                double vertex = Math.acos(top / divisor);
                vertices[j] = nf.format(Math.toDegrees(vertex));
            return vertices;
        public String[] getLengths(Polygon triangle)
            double[] lengths = getSideLengths(triangle);
            String[] lengthStrs = new String[lengths.length];
            for(int j = 0; j < lengthStrs.length; j++){
                lengthStrs[j] = nf.format(lengths[j]);
            return lengthStrs;
        public double[] getSideLengths(Polygon triangle)
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            double[] lengths = new double[SIDES];
            for(int j = 0; j < SIDES; j++)
                int next = (j + 1) % SIDES;
                lengths[j] = Point.distance(x[j], y[j], x[next], y[next]);
            return lengths;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.FontRenderContext;
    import java.awt.font.LineMetrics;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    * @author  Sharan Bhojwani
    public class InterceptView extends JPanel {
        public InterceptModel model;
        public Polygon smallTriangle;
        public Polygon bigTriangle;
        private JTable intercepttable;
        private JTable interceptTableA;
        private JTable interceptTableB;
        public JLabel centroidLabel;
        Font sideFont, vertexFont, areaFont;
        private boolean showConstruction;
        private InterceptControl interceptcontrol;
        private NumberFormat nf;
        JLabel ratLabel;
        JSlider ratSlider;
        final int ABCLABELS = 0;
        final int DEFLABELS = 1;
        JTextArea tarea2;
        final int abclabels = 0;
        final int deflabels = 1;
        final String notes[] = {
            // note 0
            "HELLOO "  ,
        public InterceptView(InterceptModel model) {
            this.model = model;
            smallTriangle = model.getSmallTriangle();
            bigTriangle = model.getBigTriangle();
            showConstruction = false;
            interceptcontrol= new InterceptControl(this);
            addMouseListener(interceptcontrol);
            addMouseMotionListener(interceptcontrol);
            sideFont = new Font("times new roman", Font.PLAIN, 14);
            vertexFont = new Font("lucida sans demibold", Font.PLAIN, 18);
            areaFont = vertexFont.deriveFont(12f);
            nf = NumberFormat.getNumberInstance();
            nf.setMaximumFractionDigits(1);
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
            g2.draw(smallTriangle);
            g2.draw(bigTriangle);
            labelTriangle(g2, smallTriangle, this.ABCLABELS);
            labelTriangle(g2, bigTriangle, this.DEFLABELS);
            //if(model.medians == null)
            //    centroidLabel.setText("centroid location: " + model.findCentroid(smallTriangle));
            // draw medians and centroid point
            if(showConstruction && !interceptcontrol.dragging) {
                g2.setPaint(Color.red);
                for(int j = 0; j < 3; j++)
                    //                g2.draw(model.medians[j]);
                    g2.setPaint(Color.blue);
                //            g2.fill(new Ellipse2D.Double(model.centroid.getX() - 2,
                //                                         model.centroid.getY() - 2, 4, 4));
        private void labelTriangle(Graphics2D g2, Polygon triangle, int labelSet) {
            // sides
            // adjacent - c
            int PAD = 10;
            g2.setFont(sideFont);
            FontRenderContext frc = g2.getFontRenderContext();
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            double[] lengths = model.getSideLengths(triangle);
            double theta = -computeAngle(lengths[0], lengths[1], lengths[2]);
            // vertices
            g2.setFont(vertexFont);
            frc = g2.getFontRenderContext();
            // A
            theta = -Math.PI/2 - computeAngle(lengths[0], lengths[1], lengths[2])/2;
            int cx = x[0] + (int)((2 * PAD) * Math.cos(theta));
            int cy = y[0] + (int)((2 * PAD) * Math.sin(theta));
            float w = (float)vertexFont.getStringBounds("A", frc).getWidth();
            LineMetrics lm = vertexFont.getLineMetrics("A", frc);
            float h = lm.getAscent();
            float sx = cx - w/2 +15 ;
            float sy = cy + h/2;
            if (labelSet == 0) {
                g2.drawString("A", sx, sy); }
            //        else if (labelSet == 1) {
            //            g2.drawString("D", sx, sy); }
            // C
            theta = Math.PI*3/4;
            cx = x[1] + (int)((2 * PAD) * Math.cos(theta));
            cy = y[1] + (int)((2 * PAD) * Math.sin(theta));
            w = (float)vertexFont.getStringBounds("C", frc).getWidth();
            lm = vertexFont.getLineMetrics("C", frc);
            h = lm.getAscent();
            sx = cx - w/2 + 2;///2;
            sy = cy - h/2 -4 ;
            if (labelSet == 0) {
                g2.drawString("C", sx, sy); }
    //        else if (labelSet == 1) {
    //            g2.drawString("E", sx, sy); }
            // C//E
            theta = computeAngle(lengths[2], lengths[0], lengths[1])/2;
            cx = x[2] + (int)((2 * PAD) * Math.cos(theta));
            cy = y[2] + (int)((2 * PAD) * Math.sin(theta));
            w = (float)vertexFont.getStringBounds("B", frc).getWidth();
            lm = vertexFont.getLineMetrics("B", frc);
            h = lm.getAscent();
            sx = cx - w   ;
            sy = cy - h/2  ;
            if (labelSet == 0) {
                g2.drawString("B", sx, sy); }
    //        else  if (labelSet == 1) {
    //            g2.drawString("D", sx, sy);
        private double computeAngle(double side, double opp, double last) {
            double top = side * side + last * last - opp * opp;
            double divisor = 2 * side * last;
            return Math.acos(top / divisor);
        public InterceptModel getModel() {
            return model;
        public JTable getInterceptTableA() {
            return interceptTableA;
        public JTable getInterceptTable(){
        return intercepttable;
        public JTable getInterceptTableB() {
            return interceptTableB;
        public JLabel getCentroidLabel() {
            return centroidLabel;
        public JPanel getUIPanel() {
            ratSlider = new JSlider(0,5,4);
            ratSlider.setPaintTicks(true);
            ratLabel = new JLabel("AB = BD = " + (5 * ratSlider.getValue()));
            ratSlider.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    ratLabel.setText("AB = BD = " + (5* ratSlider.getValue()));
                    interceptcontrol.setRatio(ratSlider.getValue());
                    //boolean state = ((JCheckBox)e.getSource()).isSelected();
                    //showConstruction = state;
                    repaint();
            JPanel panel = new JPanel();
            panel.add(ratSlider);
            panel.add(ratLabel);
            return panel;
        public JPanel getInterceptTablePanel(){
          String[] headers = new String[] { "", "", "", "" ,"",""};
            String[] rowHeaders = {
                "Sides","Lengths","Ratio","RatioValues",""
            String[] sidesRow = new String[]{"AB","AC","BC","BD","CE","DE"};
            //String[] anglesRow = { "^BAC", "^DBC", "^BCE","^BDE", "^DEC" };
            String[] sidesRatio = new String[] {"AB/BD", "", "AC/CE","","BC/CE"};
            //String[] angles  = model.getAngles(smallTriangle);
            String[] lengthsSmallTriangle = model.getLengths(smallTriangle);
            double[] doLengthsBigTri = model.getSideLengths(bigTriangle);
            double[] doLengthsSmaTri = model.getSideLengths(smallTriangle);
            int BD = (int) (doLengthsBigTri[0] - doLengthsSmaTri[0]);
            int CE = (int) (doLengthsBigTri[2] - doLengthsSmaTri[2]);
            String[] lengths = {lengthsSmallTriangle[0],lengthsSmallTriangle[2],lengthsSmallTriangle[1],
                nf.format(BD), nf.format(CE), nf.format(doLengthsBigTri[1])};
            String[] ratios = {nf.format(doLengthsSmaTri[0]/BD),"", nf.format(doLengthsSmaTri[2]/CE), "", nf.format(doLengthsSmaTri[1]/doLengthsBigTri[1])};
            String[][] allData = { sidesRow, lengths, sidesRatio, ratios };
            int rows = 4;
            int cols = 6;
            Object[][] data = new Object[rows][cols];
            for(int row = 0; row < rows; row++) {
                data[row][0] = rowHeaders[row];
                for(int col = 1; col < cols; col++)
                    data[row][col] = allData[row][col - 1];
             intercepttable = new JTable(data, headers) {
                public boolean isCellEditable(int row, int col) {
                    return false;
            DefaultTableCellRenderer renderer =
            (DefaultTableCellRenderer)intercepttable.getDefaultRenderer(String.class);
            renderer.setHorizontalAlignment(JLabel.CENTER);
            JPanel panel = new JPanel();
            panel.add(intercepttable);
            return panel;
        public JPanel getInterceptTablePanelB() {
            String[] headers = new String[] { "", "", "", "" };
            // row and column data labels
            String[] rowHeaders = {
                "sides", "lengths", "angles", "degrees"
            String[] sidesRow = { "D-E", "E-F", "F-D" };
            String[] anglesRow = { "Angle D", "Angle E", "Angle F" };
            // collect data from model
            String[] angles  = model.getAngles(smallTriangle);
            String[] lengths = model.getLengths(smallTriangle);
            String[][] allData = { sidesRow, lengths, anglesRow, angles };
            int rows = 4;
            int cols = 3;
            Object[][] data = new Object[rows][cols+1];
            for(int i = 0; i < rows; i++) {
                data[0] = rowHeaders[i];
    for(int j = 1; j <= cols; j++)
    data[i][j] = allData[i][j-1];
    interceptTableB = new JTable(data, headers) {
    public boolean isCellEditable(int row, int col) {
    return false;
    DefaultTableCellRenderer renderer =
    (DefaultTableCellRenderer)interceptTableB.getDefaultRenderer(String.class);
    renderer.setHorizontalAlignment(JLabel.CENTER);
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder("triangle DEF"));
    panel.add(interceptTableB);
    return panel;
    public JTextArea getJtextArea(){
    tarea2 = new JTextArea();
    tarea2.setText(notes[0]);
    tarea2.setSize(400,0);
    tarea2.setWrapStyleWord(true);
    tarea2.setLineWrap(true);
    return tarea2;
    public JPanel getTxtPanel(){
    JPanel panel = new JPanel(new GridLayout());
    panel.setSize(600,600);
    panel.add(getInterceptTablePanelB(), "South");
    panel.add(getJtextArea(),"East");
    return panel;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import javax.swing.JTable;
    import javax.swing.event.MouseInputAdapter;
    * @author Sharan Bhojwani
    public class InterceptControl extends MouseInputAdapter{
    InterceptView view;
    InterceptModel model;
    Point start;
    boolean dragging, altering;
    Rectangle lineLens;
    /** Creates a new instance of InterceptControl */
    public InterceptControl(InterceptView tv) {
    view = tv;
    model = view.getModel();
    dragging = altering = false;
    lineLens = new Rectangle(0, 0, 6, 6);
    public void mousePressed(MouseEvent e) {
    * Point p = e.getPoint();
    * lineLens.setLocation(p.x - 3, p.y - 3);
    * // are we over a line
    * if(model.isLineSelected(lineLens))
    * start = p;
    * altering = true;
    * // or are we within the triangle
    * else if(model.contains(p,model.getSmallTriangle()))
    * start = p;
    * dragging = true;
    void setRatio(int ratio) {
    model.setRatio(ratio);
    updateInterceptTable();
    //updateInterceptTableA();
    // updateInterceptTableB();
    public void mouseReleased(MouseEvent e) {
    altering = false;
    dragging = false;
    //view.getCentroidLabel().setText("centroid location: " +
    // model.findCentroid(model.getSmallTriangle()));
    view.repaint(); // for the construction lines
    public void mouseDragged(MouseEvent e) {
    Point p = e.getPoint();
    if(altering) {
    int x = p.x - start.x;
    int y = p.y - start.y;
    model.moveSide(x, y, p);
    updateInterceptTable();
    //updateInterceptTableA();
    // updateInterceptTableB();
    view.repaint();
    start = p;
    else if(dragging)
    int x = p.x - start.x;
    int y = p.y - start.y;
    model.translate(x, y, model.getSmallTriangle());
    //model.translate(x, y, model.getBigTriangle());
    view.repaint();
    start = p;
    //TABLE FOR FIRST TRIANLGE ABC
    private void updateInterceptTable(){
    String[] lengths = model.getLengths(model.getSmallTriangle());
    // String[] squares = model.getSquares();
    String[] angles = model.getAngles(model.getSmallTriangle());
    JTable table = view.getInterceptTable();
    for(int j = 0; j < angles.length; j++) {
    table.setValueAt(lengths[j], 1, j + 1);
    // table.setValueAt(squares[j], 2, j + 1);
    table.setValueAt(angles[j], 3, j + 1);
    //view.getCentroidLabel().setText("centroid location: " +
    Now if you compile and run these classes - u will c two triangles on screen
    ONE IS ABC AND THE OTHER WTIH VERTEX A an dsides D E -
    now D and E are not labeled coz I was having problems with the labels coz everytime i incremented the JSLIDer the triangle changed shape and the lables interchanged
    Now what I am trying to demonstrate here is the Triangle Intercept theorem which states that when BC is Parallel to DE - no matter what the size of the triangle the ratios of AB/BD = AC/AE ----
    and in my triangle i got BC as the line parallelt o DE - so i have got 2 triangles one ABC (SMALLER TRIANGLE)_ and
    ADE - Bigger triangle
    with BC appearing as the line passing through the midpoint of SIDES AD AND AE -
    I need to get the values of the ratios of the sides and i cant figure out how to calculate the values of sides AC and CE and AE - that should be updated automatically...
    Can Any one help me with this - thanks

    Hi again - The post before this is got the code for the problem at hand but the requirements have changed slightly -
    So far I have managed to draw a 2Triangles on screen -
    both are controlled by the JSlider
    I need to have my triangles fixed in a certain position on screen -
    I just need the one triangle and I need the Jslider controlling the line passing through the triangle which is parallelt o its base.
    i.e. before i had two triangles witht he base of the smaller one acting as the parallel line through the midpoints...
    now i need a line passing through the triangle not necessarily thorugh its midpoints but it should be parallel to its base..
    and the Jslider should control this line such that as it increments the line moves down and decrements it moves up
    and then the ratios can be calculated to show that AB:BD = AC:CE no matter where BC is the parallel line where the parallel line is within the triangles sides
    secondly.. the user should be able to Drag any side of the triangle by its vertex and manipulate its lengths i.e . increase or decrease the size of the triangle using is vertex
    can any one help me with his
    Thanks...

  • Four color theorem

    Does anyone know where I can find a source code for the four color theorem? Finding anything on the web is difficult, and I want to show my CMSI class to see how it properly looks like. I'd program it myself, but I have too many things to do - another job, cooking, etc. I really need help, here. Please post the link or cut and paste the code. Thanks.

    Does anyone know where I can find a source code for
    the four color theorem? Finding anything on the web is
    difficult, and I want to show my CMSI class to see how
    it properly looks like. I'd program it myself, but I
    have too many things to do - another job, cooking,
    etc. I really need help, here. Please post the link or
    cut and paste the code. Thanks.How about I write the code and come to your class and do a presentation for you. Come on,
    cough troll.

  • Central limit theorem

    hi all,
    i have made a small VI to apply the central limit theorem, it works very good except that it is slow, i know i can use a more powerful computer and it will be faster, but i want to optimize this vi for minimum time.
    anyone can help?
    what i do in this vi: 1-generate N (usualy 30) unigue random positive integer numbers
    2-i use this 30 integers as indices to select 30 random elements from an array X (which has at least 40 samples)
    3- i get the average of this 30 randomly selected elements from array X
    4- i repeat the previous 3 steps at least 10^6 times.
    5- i draw a histogram.
    is there a way to make this vi faster (as possible) , even if i have to change the algorithm, as long as it does the same.
    thank you
    Solved!
    Go to Solution.
    Attachments:
    CLT.vi ‏34 KB

    Here's what I would do.
    For 1M samples, it takes abour 2s on my computer.
    If you parallelize the outer loop, it will be proportionally faster (~0.15s total on my 16 core dual Xeon )
    Code assumes that the input array is >30 and that you want to pick 30 random elements. Change to diagram constant wired to N of the inner loop to change the pick size (or change to a control on the toplevel diagram).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    CLT_Code.png ‏5 KB
    CLT_MOD.vi ‏26 KB

  • Chinese Remainder theorem : Looking for an implementation

    Weill it's not as if it's a difficult theorem but I don't really know the algorith to make it work, though I need the result obtained by it, so I searched an already done implementation of this algorith but couldn't find it. So if anyone has an idea of where I could find it, I would be grateful...
    Thanks!

    The only way you could need this is if it has been set as homework. In which case YOU need to program the algorithm, not us. I suggest you do some more research because Google produced 'about 658,000' hits.

  • Central Slice Theorem for 2D FFT

    DO anyone know how to apply 2D Central slice theorem for 2D  Fourier Transformed Image? FOr this forst we need to mapp the samples of FT in Cartesian coordinate system to Polar.
    Can anyone help with this?
    Nghtcwrlr
    ********************Kudos are alwayzz Welcome !! ******************

Maybe you are looking for