Package cranks.geom

Examples of cranks.geom.Point


      getLink(2).getPostJoint().setCoordinates(l2*Math.cos(inputAngle.getAngle())-(l1/2),
                                         l2*Math.sin(inputAngle.getAngle()));
      getLink(4).getPostJoint().setCoordinates(l1/2, 0);
      Circle circle1 = new Circle(getLink(2).getPostJoint(), l3);
      Circle circle2 = new Circle(getLink(4).getPostJoint(), l4);
      Point newJoint = (elbowUp)?(circle1.intersect(circle2)[0]):
                                 (circle1.intersect(circle2)[1]);
      if (newJoint != null)
        getLink(3).getPostJoint().setCoordinates(newJoint.getX(), newJoint.getY());
    }
  }
View Full Code Here


                                       l2*Math.sin(inputAngle.getAngle()));
    Circle circle1 = new Circle(getLink(2).getPostJoint(), l3);
    Circle circle2 = new Circle(getLink(4).getPostJoint(), l4);
    Point[] points = circle1.intersect(circle2);
    if ((points[0] != null) && (points[1] != null)) {
      Point oldJoint = getLink(3).getPostJoint();
      Point newJoint = (points[0].distanceTo(oldJoint) <
                        points[1].distanceTo(oldJoint)) ?
                          (points[0]) : (points[1]);
      getLink(3).getPostJoint().setCoordinates(newJoint.getX(), newJoint.getY());
    }
    //Point newJoint = (elbowUp)?(circle1.intersect(circle2)[0]):
    //                           (circle1.intersect(circle2)[1]);
    //if (newJoint != null)
    //  getLink(3).getPostJoint().setCoordinates(newJoint.getX(), newJoint.getY());
View Full Code Here

              rotationRange.getStart()).getAngle() <= increment.getAngle())))
        toggleDirection();
    inputAngle.inc(increment.getAngle()*direction);
    updateJointPositions();
    if (getLink(3).isTernary()) {
      Point couplerPoint = getLink(3).getCouplerPoint();
      couplerPoint.removeAssociations();
      if (ternaryTrace.size() < numTracePoints)
        ternaryTrace.addElement(couplerPoint);
    }
  }
View Full Code Here

                               getLink(3).getPostJoint().getX(),
                               getLink(3).getPostJoint().getY()));
    if (getLink(3).isTernary()) {
      if (drawTrace) {
        for (int i = 0; i<ternaryTrace.size(); i++) {
          Point tracePoint = ternaryTrace.elementAt(i);
          g2d.setPaint(Color.red);
          g2d.fill(new Arc2D.Double(tracePoint.getX() - 2, tracePoint.getY() - 2,
                                  4, 4, 0, 360, Arc2D.OPEN));
        }
      }
      g2d.setPaint(Color.magenta);
      g2d.draw(new Line2D.Double(getLink(3).getPreviousJoint().getX(),
View Full Code Here

    dispose();
  }

  private void createCircle() {
    if (tabbedPane.getSelectedComponent() == pCentreRadius) {
      Point centre = (Point)cCentrePoint.getSelectedItem();
      Object radius;
      try {
        if (rbRadiusValue.isSelected())
          radius = new Double(Double.parseDouble(tfRadius.getText()));
        else
          radius = (GeometricalObject)cRadiusReference.getSelectedItem();
      } catch (NumberFormatException e) {
        tfRadius.selectAll();
        JOptionPane.showMessageDialog(this, "Please enter numerical value for radius",
                                      "Try Again", JOptionPane.ERROR_MESSAGE);
        tfRadius.requestFocus(true);
        return;
      }
      ConstructionStep step = new ConstructionStep(this, new Object[]{centre,
                                                        radius}, CENTRE_RADIUS);
      doConstruction(step);
    }
    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);
    }
  }
View Full Code Here

    }
  }

  public void doConstruction(ConstructionStep step) {
    if (step.getConstructionType() == CENTRE_RADIUS) {
      Point centre = (Point)step.getInputs()[0];
      Object obj1 = step.getInputs()[1];
      boolean radiusReference = (obj1 instanceof GeometricalObject);
      double radius;
      if (radiusReference) {
        if (step.getInputs()[1] instanceof Line)
          radius = ((Line)obj1).getLength();
        else
          radius = ((Circle)obj1).getRadius();
      }
      else {
        radius = ((Double)obj1).doubleValue();
        if (!(radius > 0)) {
          JOptionPane.showMessageDialog(this, "Please enter positive value for " +
                              "radius", "Try Again", JOptionPane.ERROR_MESSAGE);
          initDialog();
        }
      }
      Circle newCircle = new Circle(centre, radius);
      newCircle.addToObjects(objects);
      if (radiusReference)
        if (obj1 instanceof Line) {
          ((Line)obj1).addPropertyChangeListener(Line.PROP_LENGTH, newCircle);
          newCircle.addPropertyChangeListener(Circle.PROP_RADIUS, (Line)obj1);
        }
        else {
          ((Circle)obj1).addPropertyChangeListener(Circle.PROP_RADIUS, newCircle);
          newCircle.addPropertyChangeListener(Circle.PROP_RADIUS, (Circle)obj1);
        }
      clearAndHide();
      step.setOutputs(new Object[]{newCircle});
      fireUndoableEditUpdate(new UndoableEditEvent(this, step));
    }
    else if (step.getConstructionType() == THREE_POINTS) {
      Point point1 = (Point)step.getInputs()[0];
      Point point2 = (Point)step.getInputs()[1];
      Point point3 = (Point)step.getInputs()[2];
      Line line12 = new Line(point1, point2);
      Line line23 = new Line(point2, point3);
      if (!((line12.isParallel(line23))||(point1.equalTo(point2))
          || (point2.equalTo(point3)) || (point3.equalTo(point1))))  {
        Circle newCircle = new Circle(point1, point2, point3);
        newCircle.addToObjects(objects);
        clearAndHide();
        step.setOutputs(new Object[]{newCircle.getCentre(), newCircle});
        fireUndoableEditUpdate(new UndoableEditEvent(this, step));
View Full Code Here

    }
  }

  public void actionPerformed(ActionEvent e) {
    if (isVisible() && e.getActionCommand().equals("Point Selected")) {
      Point tempPoint = (Point)cSelectPoint.getSelectedItem();
      tfNewCoordinatesX.setText(String.valueOf(tempPoint.getX()));
      tfNewCoordinatesY.setText(String.valueOf(tempPoint.getY()));
    }
  }
View Full Code Here

  private void modifyPoint() {
    try {
      double p_x = Double.parseDouble(tfNewCoordinatesX.getText());
      double p_y = Double.parseDouble(tfNewCoordinatesY.getText());
      Point oldPoint = (Point)cSelectPoint.getSelectedItem();
      ConstructionStep step = new ConstructionStep(this,
        new Object[]{new Double(oldPoint.getX()), new Double(oldPoint.getY()),
        oldPoint, new Double(p_x), new Double(p_y)}, MODIFY_POINT);
      doConstruction(step);
    } catch (NumberFormatException e) {
      JOptionPane.showMessageDialog(this, "Please enter numerical value",
                                  "Try Again", JOptionPane.ERROR_MESSAGE);
View Full Code Here

    }
  }

  public void doConstruction(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

    }
  }

  public void undoConstruction(ConstructionStep step) {
    if (step.getConstructionType() == MODIFY_POINT) {
      Point tempPoint = (Point)step.getInputs()[2];
      tempPoint.setCoordinates(((Double)step.getInputs()[0]).doubleValue(),
                         ((Double)step.getInputs()[1]).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

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.