+ /**
+ * Returns direction vector pointing towards an adjacent component for
+ * directed control points or turn control points with one open end.
+ *
+ * Always returns an outwards pointing vector.
+ *
+ * For any other type of component, the return value is null.
+ *
+ * For turn components this only return a non-null value for the unconnected
+ * end of the component.
+ *
+ * @param direction
+ * @return normalized vector, or null
+ */
+ public Vector3d getDirection(Direction direction) {
+ if (isDirected())
+ return getDirectedControlPointDirection();
+ if (isTurn() && asFixedAngle()) {
+ if (direction == Direction.NEXT) {
+ if (previous != null) {
+ PipeControlPoint pcp = this;
+ Vector3d dir = new Vector3d();
+ dir.sub(pcp.getWorldPosition(),previous.getWorldPosition());
+ if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+ dir.normalize();
+ else
+ return null;
+ Quat4d q = getControlPointOrientationQuat(dir, pcp.getRotationAngle() != null ? pcp.getRotationAngle() : 0.0);
+ AxisAngle4d aa = new AxisAngle4d(MathTools.Y_AXIS,pcp.getTurnAngle() == null ? 0.0 : pcp.getTurnAngle());
+ Quat4d q2 = MathTools.getQuat(aa);
+ Vector3d v = new Vector3d(1.,0.,0.);
+ Vector3d offset = new Vector3d();
+ MathTools.rotate(q2, v, offset);
+ MathTools.rotate(q, offset, dir);
+ dir.normalize();
+ return dir;
+ }
+ } else {
+ if (next != null) {
+ PipeControlPoint pcp = this;
+ Vector3d dir = new Vector3d();
+ dir.sub(next.getWorldPosition(),pcp.getWorldPosition());
+ if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+ dir.normalize();
+ else
+ return null;
+ Quat4d q = getControlPointOrientationQuat(dir, pcp.getRotationAngle() != null ? pcp.getRotationAngle() : 0.0);
+ AxisAngle4d aa = new AxisAngle4d(MathTools.Y_AXIS,pcp.getTurnAngle() == null ? 0.0 : pcp.getTurnAngle());
+ Quat4d q2 = MathTools.getQuat(aa);
+ Vector3d v = new Vector3d(1.,0.,0.);
+ Vector3d offset = new Vector3d();
+ MathTools.rotate(q2, v, offset);
+ MathTools.rotate(q, offset, dir);
+ dir.negate();
+ dir.normalize();
+ return dir;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns path leg direction of the control point.
+ *
+ * This method differs from getDirection by also returning inward pointing vectors for directed control points.
+ *
+ * @param direction
+ * @return
+ */