Search in sources :

Example 1 with Vector3

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

the class ConnectorSkeleton method pointOnShapeAndPerpendicular.

/**
 * Compute a point at a given percent on the shape and push it from the shape perpendicular
 * to it at a given distance in GU. The percent must be a number between 0 and 1. The result
 * is stored in target and also returned.
 */
public Point3 pointOnShapeAndPerpendicular(double percent, double perpendicular, Point3 target) {
    double at = percent;
    if (percent > 1)
        at = 1;
    if (at < 0)
        at = 0;
    if (isCurve()) {
        Point3 p0 = points.get(0);
        Point3 p1 = points.get(1);
        Point3 p2 = points.get(2);
        Point3 p3 = points.get(3);
        Vector2 perp = CubicCurve.perpendicular(p0, p1, p2, p3, at);
        perp.normalize();
        perp.scalarMult(perpendicular);
        target.x = CubicCurve.eval(p0.x, p1.x, p2.x, p3.x, at) - perp.data[0];
        target.y = CubicCurve.eval(p0.y, p1.y, p2.y, p3.y, at) - perp.data[1];
        target.z = 0;
    } else if (isPoly()) {
        Triplet<Integer, Double, Double> triplet = wichSegment(at);
        int i = triplet.i;
        double sum = triplet.sum;
        double ps = triplet.ps;
        Vector3 dir = new Vector3(points.get(i + 1).x - points.get(i).x, points.get(i + 1).y - points.get(i).y, 0);
        Vector3 perp = new Vector3(dir.data[1], -dir.data[0], 0);
        perp.normalize();
        perp.scalarMult(perpendicular);
        dir.scalarMult(ps);
        target.set(points.get(i).x + dir.data[0] + perp.data[0], points.get(i).y + dir.data[1] + perp.data[1], points.get(i).z);
    } else {
        Vector3 dir = new Vector3(to().x - from().x, to().y - from().y, 0);
        Vector3 perp = new Vector3(dir.data[1], -dir.data[0], 0);
        perp.normalize();
        perp.scalarMult(perpendicular);
        dir.scalarMult(at);
        target.set(from().x + dir.data[0] + perp.data[0], from().y + dir.data[1] + perp.data[1], from().z);
    }
    return target;
}
Also used : Point3(org.graphstream.ui.geom.Point3) Vector2(org.graphstream.ui.geom.Vector2) Vector3(org.graphstream.ui.geom.Vector3)

Aggregations

Point3 (org.graphstream.ui.geom.Point3)1 Vector2 (org.graphstream.ui.geom.Vector2)1 Vector3 (org.graphstream.ui.geom.Vector3)1