本文整理汇总了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;
}
示例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;
}
示例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));
}
}
}