當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector3d.scaleAdd方法代碼示例

本文整理匯總了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
}
 
開發者ID:BenzclyZhang,項目名稱:BimSPARQL,代碼行數:67,代碼來源:Distance.java


注:本文中的javax.vecmath.Vector3d.scaleAdd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。