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


Java PApplet.sqrt方法代碼示例

本文整理匯總了Java中processing.core.PApplet.sqrt方法的典型用法代碼示例。如果您正苦於以下問題:Java PApplet.sqrt方法的具體用法?Java PApplet.sqrt怎麽用?Java PApplet.sqrt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在processing.core.PApplet的用法示例。


在下文中一共展示了PApplet.sqrt方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: intersectionParabolas

import processing.core.PApplet; //導入方法依賴的package包/類
PVector intersectionParabolas(PVector p0, PVector p1, float l) {
	PVector res = new PVector(), p = p0;
	if (p0.x == p1.x)
		res.y = (p0.y + p1.y) / 2;
	else if (p1.x == l)
		res.y = p1.y;
	else if (p0.x == l) {
		res.y = p0.y;
		p = p1;
	} else {
		float s0 = 2 * (p0.x - l), s1 = 2 * (p1.x - l);
		float a = 1 / s0 - 1 / s1;
		float b = -2 * (p0.y / s0 - p1.y / s1);
		float c = (p0.y * p0.y + p0.x * p0.x - l * l) / s0 - (p1.y * p1.y + p1.x * p1.x - l * l) / s1;
		res.y = (-b - PApplet.sqrt(b * b - 4 * a * c)) / (2 * a);
	}
	res.x = (p.x * p.x + (p.y - res.y) * (p.y - res.y) - l * l) / (2 * p.x - 2 * l);
	return res;
}
 
開發者ID:abuzreq,項目名稱:ConstrainedGraphPartitioning,代碼行數:20,代碼來源:VoronoiGenerator.java

示例2: computeCircle

import processing.core.PApplet; //導入方法依賴的package包/類
CircleResponse computeCircle(PVector a, PVector b, PVector c) {
	// BC must be a right turn from AB
	if ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y) > 0)
		return new CircleResponse(false);

	// Algorithm from O'Rourke 2ed p. 189.
	float A = b.x - a.x, B = b.y - a.y, C = c.x - a.x, D = c.y - a.y, E = A * (a.x + b.x) + B * (a.y + b.y), F = C
			* (a.x + c.x) + D * (a.y + c.y), G = 2 * (A * (c.y - b.y) - B * (c.x - b.x));

	// co-linear
	if (G == 0)
		return new CircleResponse(false);

	// p is the center
	CircleResponse r = new CircleResponse(true);
	r.p.x = (D * E - B * F) / G;
	r.p.y = (A * F - C * E) / G;

	// max x coordinate
	r.x = r.p.x + PApplet.sqrt(PApplet.pow(a.x - r.p.x, 2) + PApplet.pow(a.y - r.p.y, 2));
	return r;
}
 
開發者ID:abuzreq,項目名稱:ConstrainedGraphPartitioning,代碼行數:23,代碼來源:VoronoiGenerator.java

示例3: WuerfelRahmen

import processing.core.PApplet; //導入方法依賴的package包/類
WuerfelRahmen(PApplet p) {
	parent = p;
	int anzZ = (int) PApplet.sqrt(anzW);
	int anzS = anzZ;
	int anzL = 0;
	if (anzS * anzZ < anzW) {
		anzS++;
		anzL = anzW - anzS * (anzZ - 1);
		w = p.width;
	}

	if (parent.height < w)
		w = parent.height;
	int s = (w - (anzS + 1) * wuerfelAbstand) / anzS;
	// int f = (w -(s+wuerfelAbstand) * anzL) /2;
	// xx if (anzL == 0) f = wuerfelAbstand;

	for (int j = 0; j < anzZ; j++) {
		for (int i = 0; i < anzS; i++) {
			int x = (wuerfelAbstand + s) * i + wuerfelAbstand;
			int y = (wuerfelAbstand + s) * j + wuerfelAbstand;
			if (anzL != 0 && j == anzZ - 1) {
				if (i >= anzL)
					break;
				// ... x = (wuerfelAbstand + s) * i + f; // HLU 19.5.17 line
				// commented
			}
			wuerfelListe.add(new Wuerfel(x, y, s, parent));
		}
	}
}
 
開發者ID:CoffeeCodeSwitzerland,項目名稱:Lernkartei_2017,代碼行數:32,代碼來源:WuerfelRahmen.java


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