Package cranks.geom

Examples of cranks.geom.Point


    }
  }

  public void redoConstruction(ConstructionStep step) {
    if (step.getConstructionType() == MODIFY_POINT) {
      Point tempPoint = (Point)step.getInputs()[2];
      tempPoint.setCoordinates(((Double)step.getInputs()[3]).doubleValue(),
                         ((Double)step.getInputs()[4]).doubleValue());
      Vector<GeometricalObject> assocObjects = tempPoint.getAssocObjects();
      for (int i = 0; i<assocObjects.size(); i++) {
        GeometricalObject o = assocObjects.elementAt(i);
        if (o.getType() == Line.TYPE)
          ((Line)o).setLengthAndSlope();
      }
View Full Code Here


        object = new DefaultMutableTreeNode(String.valueOf(o.getNumber()));
        top.add(object);

        switch (type) {
          case 2: //point
            Point p = ((Point)o);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("X Co-ordinate", p.getX()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Y Co-ordinate", p.getY()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Visibility", p.isVisible()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("AssociatedObjects", "Empty"));
            object.add(field);
            assocObjects = p.getAssocObjects();
            for (int j = 0; j<assocObjects.size(); j++) {
              GeometricalObject ob = assocObjects.elementAt(j);
              subField = new DefaultMutableTreeNode(
                new FieldInfo(Integer.toString(ob.getNumber()), ob));
              field.add(subField);
View Full Code Here

          length = (GeometricalObject)cLengthReference.getSelectedItem();
        if (rbSlopeValue.isSelected())
          slopeDegrees = new Double(Double.parseDouble(tfSlope.getText()));
        else
          slopeDegrees = (GeometricalObject)cSlopeReference.getSelectedItem();
        Point p = (Point)cPoint.getSelectedItem();
        step = new ConstructionStep(this, new Object[]{p, length,
                            slopeDegrees}, ONE_POINT);
        doConstruction(step);
      } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(this, "Please enter numerical value",
                                    "Try Again", JOptionPane.ERROR_MESSAGE);
        return;
      }
    }
    if(tabbedPane.getSelectedComponent() == pTwoPoints) {///2 point
      Point p1 = (Point)cPoint1.getSelectedItem();
      Point p2 = (Point)cPoint2.getSelectedItem();
      step = new ConstructionStep(this, new Object[]{p1, p2}, TWO_POINTS);
      doConstruction(step);
    }
  }
View Full Code Here

    }
  }

  public void doConstruction(ConstructionStep step) {
    if (step.getConstructionType() == ONE_POINT) {
      Point p = (Point)step.getInputs()[0];
      Object obj1 = step.getInputs()[1];
      Object obj2 = step.getInputs()[2];
      boolean lengthReference = (obj1 instanceof GeometricalObject);
      boolean slopeReference = (obj2 instanceof GeometricalObject);
      double length;
      Angle slope;
      if (lengthReference) {
        if (step.getInputs()[1] instanceof Line)
          length = ((Line)obj1).getLength();
        else
          length = ((Circle)obj1).getRadius();
      }
      else {
        length = ((Double)obj1).doubleValue();
        if (!(Math.abs(length) > 0)) {
          JOptionPane.showMessageDialog(this, "Please enter non-zero value for Length",
                    "Try Again", JOptionPane.ERROR_MESSAGE);
          initDialog();
        }
      }
      if (slopeReference)
        slope = new Angle(((Line)obj2).getSlope().getAngle());
      else {
        double slopeDegrees = ((Double)obj2).doubleValue();
        slope = new Angle(Math.toRadians(slopeDegrees));
      }
      Line newLine = new Line(p, slope, length);
      newLine.addToObjects(objects);
      if (lengthReference)
        if (obj1 instanceof Line) {
          ((Line)obj1).addPropertyChangeListener(Line.PROP_LENGTH, newLine);
          newLine.addPropertyChangeListener(Line.PROP_LENGTH, (Line)obj1);
        }
        else {
          ((Circle)obj1).addPropertyChangeListener(Circle.PROP_RADIUS, newLine);
          newLine.addPropertyChangeListener(Circle.PROP_RADIUS, (Circle)obj1);
        }
      if (slopeReference) {
        ((Line)obj2).addPropertyChangeListener(Line.PROP_ANGLE, newLine);
        newLine.addPropertyChangeListener(Line.PROP_ANGLE, (Line)obj2);
      }       
      clearAndHide();
      step.setOutputs(new Object[]{newLine.getEnd(), newLine});
      fireUndoableEditUpdate(new UndoableEditEvent(this, step));
    }
    else if (step.getConstructionType() == TWO_POINTS) {
      Point p1 = (Point)step.getInputs()[0];
      Point p2 = (Point)step.getInputs()[1];
      if (!p1.equalTo(p2)) {
        Line newLine = new Line(p1, p2);
        newLine.addToObjects(objects);
        clearAndHide();
        step.setOutputs(new Object[]{newLine});
View Full Code Here

    }
  }

  private void createTriangle() {
    if (tabbedPane.getSelectedComponent() == pThreePoints) {
      Point point1 = (Point)cPoint1.getSelectedItem();
      Point point2 = (Point)cPoint2.getSelectedItem();
      Point point3 = (Point)cPoint3.getSelectedItem();
      ConstructionStep step = new ConstructionStep(this, new Object[]{point1,
                          point2, point3}, THREE_POINTS);
      doConstruction(step);
    }
    if (tabbedPane.getSelectedComponent() == pPointLine) {
      Point vertexPoint = (Point)cPoint.getSelectedItem();
      Line edgeLine = (Line)cLine.getSelectedItem();
      ConstructionStep step = new ConstructionStep(this,
                          new Object[]{vertexPoint, edgeLine}, POINT_LINE);
      doConstruction(step);
    }
View Full Code Here

    }
  }

  public void doConstruction(ConstructionStep step) {
    if (step.getConstructionType() == THREE_POINTS) {
      Point P1 = (Point)step.getInputs()[0];
      Point P2 = (Point)step.getInputs()[1];
      Point P3 = (Point)step.getInputs()[2];
      Line line12 = new Line(P1, P2);
      Line line23 = new Line(P2, P3);
      if (!((line12.getSlope().equalTo(line23.getSlope()))||(P1.equalTo(P2))
          || (P2.equalTo(P3)) || (P3.equalTo(P1))))  {
        Triangle newTriangle = new Triangle(P1, P2, P3);
        newTriangle.addToObjects(objects);
        clearAndHide();
        step.setOutputs(new Object[]
             {newTriangle.getSides()[0], newTriangle.getSides()[1],
              newTriangle.getSides()[2], newTriangle});
        fireUndoableEditUpdate(new UndoableEditEvent(this, step));
      }
      else {
        JOptionPane.showMessageDialog(this, "Please select three distinct"+
              " non-collinear points", "Try Again", JOptionPane.ERROR_MESSAGE);
        initDialog();
      }
    }
    else if (step.getConstructionType() == POINT_LINE) {
      Point P1 = (Point)step.getInputs()[0];
      Line L1 = (Line)step.getInputs()[1];
      if (!(P1.canIntersect(L1))) {
        Triangle newTriangle = new Triangle(P1, L1);
        newTriangle.addToObjects(objects);
        clearAndHide();
        step.setOutputs(new Object[]
          {newTriangle.getSides()[1], newTriangle.getSides()[2], newTriangle});
View Full Code Here

    }
  }

  public void doConstruction(ConstructionStep step) {
    if (step.getConstructionType() == ADD_POINT) {
      Point newPoint = new Point(((Double)step.getInputs()[0]).doubleValue(),
                        ((Double)step.getInputs()[1]).doubleValue());
      newPoint.addToObjects(objects);
      clearAndHide();
      step.setOutputs(new Object[]{newPoint});
      fireUndoableEditUpdate(new UndoableEditEvent(this, step));
    }
    else {
View Full Code Here

      Line selectedSide = (Line)step.getInputs()[1];
      Line newSide = (Line)step.getInputs()[2];
      boolean orientation = ((Boolean)step.getInputs()[3]).booleanValue();
      if (Math.abs(selectedSide.getLength()-newSide.getLength()) < Point.LEAST_COUNT) {
        Point[] vertices = tri.getVertices();
        Point ptOppSelSide = new Point();
        if (vertices[0].canIntersect(selectedSide))
          if (vertices[1].canIntersect(selectedSide))
            ptOppSelSide.setCoordinates(vertices[2].getX(), vertices[2].getY());
          else
            ptOppSelSide.setCoordinates(vertices[1].getX(), vertices[1].getY());
        else
          ptOppSelSide.setCoordinates(vertices[0].getX(), vertices[0].getY());

        Line line1 = (orientation)?
                  (new Line(selectedSide.getStart(), newSide.getStart())):
                  (new Line(selectedSide.getStart(), newSide.getEnd()));
        Line line2 = (orientation)?
                  (new Line(selectedSide.getEnd(), newSide.getEnd())):
                  (new Line(selectedSide.getEnd(), newSide.getStart()));
        Point centreOfRotation;
        Angle angleOfRotation;
        if (line1.getLength() < Point.LEAST_COUNT) {
          centreOfRotation = new Point(line1.getStart().getX(),line1.getStart().getY());
          angleOfRotation = (new Line(centreOfRotation, line2.getEnd())).getSlope().
                    sub((new Line(centreOfRotation, line2.getStart())).getSlope());
        }
        else if (line2.getLength() < Point.LEAST_COUNT) {
          centreOfRotation = new Point(line2.getStart().getX(),line2.getStart().getY());
          angleOfRotation = (new Line(centreOfRotation, line1.getEnd())).getSlope().
                    sub((new Line(centreOfRotation, line1.getStart())).getSlope());
        }
        else {
          Line perpLine1 = new Line(line1.midPoint(),line1.getSlope().
                              add(new Angle(Math.PI/2)),1);
          Line perpLine2 = new Line(line2.midPoint(),line2.getSlope().
                              add(new Angle(Math.PI/2)),1);
          if (perpLine1.canIntersect(perpLine2)) {
            centreOfRotation = perpLine1.intersect(perpLine2)[0];
            angleOfRotation = (new Line(centreOfRotation, line1.getEnd())).getSlope().
                    sub((new Line(centreOfRotation, line1.getStart())).getSlope());
          }
          else {
            Point translation = new Point(
                      line1.getEnd().getX() - line1.getStart().getX(),
                      line1.getEnd().getY() - line1.getStart().getY());
            ptOppSelSide.move(translation, new Angle(0), new Point());
            Triangle newTriangle = new Triangle(ptOppSelSide, newSide);
            newTriangle.addToObjects(objects);
            clearAndHide();
            step.setOutputs(new Object[]{ptOppSelSide, newTriangle.getSides()[1],
                        newTriangle.getSides()[2], newTriangle});
            fireUndoableEditUpdate(new UndoableEditEvent(this, step));
            return;
          }
        }
        ptOppSelSide.move(new Point(), angleOfRotation, centreOfRotation);
        Triangle newTriangle = new Triangle(ptOppSelSide, newSide);
        newTriangle.addToObjects(objects);
        clearAndHide();
        step.setOutputs(new Object[]{ptOppSelSide, newTriangle.getSides()[1],
                    newTriangle.getSides()[2], newTriangle});
View Full Code Here

        JOptionPane.showMessageDialog(this, "Ternary link is not connected to "+
                  "mechanism", "Try Again", JOptionPane.ERROR_MESSAGE);
        return;
      }
      Line link2 = (fixed == 4)?lines[0]:lines[(fixed - 1) + 1];
      Point intersectionOfLink2Link3 = (test(link3.getStart(), link2))?
                  (link3.getStart()):(link3.getEnd());
      Line ternaryLine = null;
      for (int i = 0; i<3; i++)
        if ( test(intersectionOfLink2Link3, ternaryLink.getSides()[i]) &&
             !ternaryLink.getSides()[i].equals(link3))
View Full Code Here

  private void setElbowStatus(Line[] lines, int fixed) {
    int lineNumber1 = fixed - 1;
    int lineNumber2 = (fixed == 4) ? 0 : fixed;
    int lineNumber3 = (fixed > 2) ? (fixed - 3) : (fixed + 1);
    int lineNumber4 = (fixed == 1) ? 3 : (fixed - 2);
    Point joint23 = lines[lineNumber2].intersect(lines[lineNumber3])[0];
    Point joint34 = lines[lineNumber3].intersect(lines[lineNumber4])[0];
    Point joint41 = lines[lineNumber4].intersect(lines[lineNumber1])[0];
    Circle circleLink3 = new Circle(joint23, lines[lineNumber3].getLength());
    Circle circleLink4 = new Circle(joint41, lines[lineNumber4].getLength());
    mechanism.setElbow(joint34.equalTo(circleLink3.intersect(circleLink4)[0]));
  }
View Full Code Here

TOP

Related Classes of cranks.geom.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.