@Test public void distanceVertexSegment() throws Exception { float[] start = {0, 1, 0, 1}; float[] end = {5, 1, 0, 1}; float[] vertex = {3, 0, 0, 1}; float res = Vector3D.distancevertexSegment(vertex, start, end); assertTrue(equal(res, 1)); float[] vertex2 = {0, 0, 0}; res = Vector3D.distancevertexSegment(vertex2, start, end); assertTrue(equal(res, 1)); float[] vertex3 = {-1, 0, 0}; res = Vector3D.distancevertexSegment(vertex3, start, end); assertTrue(equal(res, 1.4142f)); float[] start2 = {-3f, 2, -5f}; float[] end2 = {3, 2, 5}; res = Vector3D.distancevertexSegment(vertex2, start2, end2); assertTrue(equal(res, 2)); }
public static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd) { float[] vecSegment = createVector(segmentStart, segmentEnd); float[] vecDot = createVector(segmentStart, dot); float scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentStart); } vecSegment = createVector(segmentEnd, segmentStart); vecDot = createVector(segmentEnd, dot); scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentEnd); } return distanceDotLine(dot, segmentStart, segmentEnd); }
Vector3D { public static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd) { float[] vecSegment = createVector(segmentStart, segmentEnd); float[] vecDot = createVector(segmentStart, dot); float scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentStart); } vecSegment = createVector(segmentEnd, segmentStart); vecDot = createVector(segmentEnd, dot); scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentEnd); } return distanceDotLine(dot, segmentStart, segmentEnd); } }
Vector3D { public static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd) { float[] vecSegment = createVector(segmentStart, segmentEnd); float[] vecDot = createVector(segmentStart, dot); float scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentStart); } vecSegment = createVector(segmentEnd, segmentStart); vecDot = createVector(segmentEnd, dot); scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentEnd); } return distanceDotLine(dot, segmentStart, segmentEnd); }  }
Vector3D { public static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd) { float[] vecSegment = createVector(segmentStart, segmentEnd); float[] vecDot = createVector(segmentStart, dot); float scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentStart); } vecSegment = createVector(segmentEnd, segmentStart); vecDot = createVector(segmentEnd, dot); scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentEnd); } return distanceDotLine(dot, segmentStart, segmentEnd); }  static float[] vectorMultiply(float[] lhs, float[] rhs); static float scalarMultiply(float[] lhs, float[] rhs); static float distanceVertices(float[] left, float[] right); static float vectorLength(float[] vector); static float[] createVector(float[] start, float[] end); static float distanceDotLine(float[] dot, float[] lineA, float[] lineB); static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd); }
Vector3D { public static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd) { float[] vecSegment = createVector(segmentStart, segmentEnd); float[] vecDot = createVector(segmentStart, dot); float scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentStart); } vecSegment = createVector(segmentEnd, segmentStart); vecDot = createVector(segmentEnd, dot); scalarMul = scalarMultiply(vecSegment, vecDot); if ((Math.abs(scalarMul) < Epsilon) || (scalarMul < 0)) { return distanceVertices(dot, segmentEnd); } return distanceDotLine(dot, segmentStart, segmentEnd); }  static float[] vectorMultiply(float[] lhs, float[] rhs); static float scalarMultiply(float[] lhs, float[] rhs); static float distanceVertices(float[] left, float[] right); static float vectorLength(float[] vector); static float[] createVector(float[] start, float[] end); static float distanceDotLine(float[] dot, float[] lineA, float[] lineB); static float distancevertexSegment(float[] dot, float[] segmentStart, float[] segmentEnd); static final float Epsilon; }