Search in sources :

Example 6 with Point2

use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.

the class ImageOnEdge method makeOnCurve.

private void makeOnCurve(boolean forShadow, DefaultCamera2D camera) {
    Tuple<Point2, Double> tuple = CubicCurve.approxIntersectionPointOnCurve(theEdge, theConnector, camera);
    Point2 p1 = tuple.x;
    double t = tuple.y;
    Style style = theEdge.getStyle();
    Point3 p2 = CubicCurve.eval(theConnector.fromPos(), theConnector.byPos1(), theConnector.byPos2(), theConnector.toPos(), t - 0.1f);
    Vector2 dir = new Vector2(p1.x - p2.x, p1.y - p2.y);
    dir.normalize();
    double iw = camera.getMetrics().lengthToGu(image.getWidth(), Units.PX) / 2;
    double x = p1.x - (dir.x() * iw);
    double y = p1.y - (dir.y() * iw);
    if (forShadow) {
        x += shadowable.theShadowOff.x;
        y += shadowable.theShadowOff.y;
    }
    p = camera.transformGuToPx(x, y, 0);
    angle = Math.acos(dir.dotProduct(1, 0));
    if (dir.y() > 0)
        angle = (Math.PI - angle);
}
Also used : Point3(org.graphstream.ui.geom.Point3) Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Style(org.graphstream.ui.graphicGraph.stylesheet.Style)

Example 7 with Point2

use of org.graphstream.ui.geom.Point2 in project gs-ui-javafx by graphstream.

the class CubicCurve method approxLengthOfCurve.

/**
 * Evaluate the length of a Bézier curve by taking n points on the curve and summing the lengths of
 * the n+1 segments thus defined.
 */
public static double approxLengthOfCurve(Connector c) {
    double inc = 0.1;
    double i = inc;
    double len = 0.0;
    Point2 p0 = c.fromPos();
    while (i < 1f) {
        Point2 p = CubicCurve.eval(c.fromPos(), c.byPos1(), c.byPos2(), c.toPos(), i);
        i += inc;
        len += p0.distance(p);
        p0 = p;
    }
    len += p0.distance(c.toPos());
    return len;
}
Also used : Point2(org.graphstream.ui.geom.Point2)

Aggregations

Point2 (org.graphstream.ui.geom.Point2)7 Vector2 (org.graphstream.ui.geom.Vector2)5 Style (org.graphstream.ui.graphicGraph.stylesheet.Style)4 Point3 (org.graphstream.ui.geom.Point3)3 Path2D (org.graphstream.ui.javafx.renderer.shape.javafx.baseShapes.Form.Path2D)2 Point2D (javafx.geometry.Point2D)1 GraphicEdge (org.graphstream.ui.graphicGraph.GraphicEdge)1 GraphicNode (org.graphstream.ui.graphicGraph.GraphicNode)1