本文整理汇总了Java中javax.vecmath.Vector3d.scaleAdd方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3d.scaleAdd方法的具体用法?Java Vector3d.scaleAdd怎么用?Java Vector3d.scaleAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.vecmath.Vector3d
的用法示例。
在下文中一共展示了Vector3d.scaleAdd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: distanceSegmentSegment3D
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
private static double distanceSegmentSegment3D(Segment s1, Segment s2) {
Vector3d u = GeometryUtils.vectorSubtract(s1.p1.asPoint3d(),s1.p0.asPoint3d());
Vector3d v = GeometryUtils.vectorSubtract(s2.p1.asPoint3d(),s2.p0.asPoint3d());
Vector3d w = GeometryUtils.vectorSubtract(s1.p0.asPoint3d(),s2.p0.asPoint3d());
double a = u.dot(u);
double b = u.dot(v);
double c = v.dot(v);
double d = u.dot(w);
double e = v.dot(w);
double D = a * c - b * b;
double sc, sN, sD = D;
double tc, tN, tD = D;
// compute the line parameters of the two closest points
if (D < EPS) { // the lines are almost parallel
sN = 0.0; // force using point P0 on segment S1
sD = 1.0; // to prevent possible division by 0.0 later
tN = e;
tD = c;
} else { // get the closest points on the infinite lines
sN = (b * e - c * d);
tN = (a * e - b * d);
if (sN < 0.0) { // sc < 0 => the s=0 edge is visible
sN = 0.0;
tN = e;
tD = c;
} else if (sN > sD) { // sc > 1 => the s=1 edge is visible
sN = sD;
tN = e + b;
tD = c;
}
}
if (tN < 0.0) { // tc < 0 => the t=0 edge is visible
tN = 0.0;
// recompute sc for this edge
if (-d < 0.0)
sN = 0.0;
else if (-d > a)
sN = sD;
else {
sN = -d;
sD = a;
}
} else if (tN > tD) { // tc > 1 => the t=1 edge is visible
tN = tD;
// recompute sc for this edge
if ((-d + b) < 0.0)
sN = 0;
else if ((-d + b) > a)
sN = sD;
else {
sN = (-d + b);
sD = a;
}
}
// finally do the division to get sc and tc
sc = (Math.abs(sN) < EPS ? 0.0 : sN / sD);
tc = (Math.abs(tN) < EPS ? 0.0 : tN / tD);
u.scaleAdd(sc, w);
v.scale(tc);
Vector3d dP = GeometryUtils.vectorSubtract(u, v);
return dP.length(); // return the closest distance
}