@Override // from IQuaternion public float getRotationZ () { return FloatMath.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z)); }
@Override // from IQuaternion public float getRotationZ () { return FloatMath.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z)); }
@Override // from IQuaternion public Vector3 toAngles (Vector3 result) { float sy = 2f*(y*w - x*z); if (sy < 1f - MathUtil.EPSILON) { if (sy > -1 + MathUtil.EPSILON) { return result.set(FloatMath.atan2(y*z + x*w, 0.5f - (x*x + y*y)), FloatMath.asin(sy), FloatMath.atan2(x*y + z*w, 0.5f - (y*y + z*z))); } else { // not a unique solution; x + z = atan2(-m21, m11) return result.set(0f, -MathUtil.HALF_PI, FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } } else { // not a unique solution; x - z = atan2(-m21, m11) return result.set(0f, MathUtil.HALF_PI, -FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } }
@Override // from IQuaternion public Vector3 toAngles (Vector3 result) { float sy = 2f*(y*w - x*z); if (sy < 1f - MathUtil.EPSILON) { if (sy > -1 + MathUtil.EPSILON) { return result.set(FloatMath.atan2(y*z + x*w, 0.5f - (x*x + y*y)), FloatMath.asin(sy), FloatMath.atan2(x*y + z*w, 0.5f - (y*y + z*z))); } else { // not a unique solution; x + z = atan2(-m21, m11) return result.set(0f, -MathUtil.HALF_PI, FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } } else { // not a unique solution; x - z = atan2(-m21, m11) return result.set(0f, MathUtil.HALF_PI, -FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } }
@Override // from interface IVector public float angle () { return FloatMath.atan2(y(), x()); }
@Override // from interface IVector public float angle () { return FloatMath.atan2(y(), x()); }
return FloatMath.atan2(n01, n00);
return FloatMath.atan2(n01, n00);
@Override // from interface IPoint public float direction (XY other) { return FloatMath.atan2(other.y() - y(), other.x() - x()); }
@Override // from interface IPoint public float direction (XY other) { return FloatMath.atan2(other.y() - y(), other.x() - x()); }
/** * Sets the starting angle and angular extent of this arc using two sets of coordinates. The * first set of coordinates is used to determine the angle of the starting point relative to * the arc's center. The second set of coordinates is used to determine the angle of the end * point relative to the arc's center. The arc will always be non-empty and extend * counterclockwise from the first point around to the second point. */ public void setAngles (float x1, float y1, float x2, float y2) { float cx = centerX(); float cy = centerY(); float a1 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx))); float a2 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx))); a2 -= a1; if (a2 <= 0f) { a2 += 360f; } setAngleStart(a1); setAngleExtent(a2); }
/** * Sets the starting angle and angular extent of this arc using two sets of coordinates. The * first set of coordinates is used to determine the angle of the starting point relative to * the arc's center. The second set of coordinates is used to determine the angle of the end * point relative to the arc's center. The arc will always be non-empty and extend * counterclockwise from the first point around to the second point. */ public void setAngles (float x1, float y1, float x2, float y2) { float cx = centerX(); float cy = centerY(); float a1 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx))); float a2 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx))); a2 -= a1; if (a2 <= 0f) { a2 += 360f; } setAngleStart(a1); setAngleExtent(a2); }
/** * Sets the starting angle of this arc to the angle defined by the supplied point relative to * the center of this arc. */ public void setAngleStart (XY point) { float angle = FloatMath.atan2(point.y() - centerY(), point.x() - centerX()); setAngleStart(normAngle(-FloatMath.toDegrees(angle))); }
/** * Sets the starting angle of this arc to the angle defined by the supplied point relative to * the center of this arc. */ public void setAngleStart (XY point) { float angle = FloatMath.atan2(point.y() - centerY(), point.x() - centerX()); setAngleStart(normAngle(-FloatMath.toDegrees(angle))); }
/** * Sets the location, size, angular extents, and closure type of this arc based on the * specified values. */ public void setArcByTangent (XY p1, XY p2, XY p3, float radius) { // use simple geometric calculations of arc center, radius and angles by tangents float a1 = -FloatMath.atan2(p1.y() - p2.y(), p1.x() - p2.x()); float a2 = -FloatMath.atan2(p3.y() - p2.y(), p3.x() - p2.x()); float am = (a1 + a2) / 2f; float ah = a1 - am; float d = radius / Math.abs(FloatMath.sin(ah)); float x = p2.x() + d * FloatMath.cos(am); float y = p2.y() - d * FloatMath.sin(am); ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah; a1 = normAngle(FloatMath.toDegrees(am - ah)); a2 = normAngle(FloatMath.toDegrees(am + ah)); float delta = a2 - a1; if (delta <= 0f) { delta += 360f; } setArcByCenter(x, y, radius, a1, delta, type); }
/** * Sets the location, size, angular extents, and closure type of this arc based on the * specified values. */ public void setArcByTangent (XY p1, XY p2, XY p3, float radius) { // use simple geometric calculations of arc center, radius and angles by tangents float a1 = -FloatMath.atan2(p1.y() - p2.y(), p1.x() - p2.x()); float a2 = -FloatMath.atan2(p3.y() - p2.y(), p3.x() - p2.x()); float am = (a1 + a2) / 2f; float ah = a1 - am; float d = radius / Math.abs(FloatMath.sin(ah)); float x = p2.x() + d * FloatMath.cos(am); float y = p2.y() - d * FloatMath.sin(am); ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah; a1 = normAngle(FloatMath.toDegrees(am - ah)); a2 = normAngle(FloatMath.toDegrees(am + ah)); float delta = a2 - a1; if (delta <= 0f) { delta += 360f; } setArcByCenter(x, y, radius, a1, delta, type); }
/** * Fills a line between the specified coordinates, of the specified display unit width. */ public Surface drawLine (float x0, float y0, float x1, float y1, float width) { // swap the line end points if x1 is less than x0 if (x1 < x0) { float temp = x0; x0 = x1; x1 = temp; temp = y0; y0 = y1; y1 = temp; } float dx = x1 - x0, dy = y1 - y0; float length = FloatMath.sqrt(dx * dx + dy * dy); float wx = dx * (width / 2) / length; float wy = dy * (width / 2) / length; AffineTransform xf = new AffineTransform(); xf.setRotation(FloatMath.atan2(dy, dx)); xf.setTranslation(x0 + wy, y0 - wx); Transforms.multiply(tx(), xf, xf); if (patternTex != null) { batch.addQuad(patternTex, tint, xf, 0, 0, length, width); } else { batch.addQuad(colorTex, Tint.combine(fillColor, tint), xf, 0, 0, length, width); } return this; }
/** * Fills a line between the specified coordinates, of the specified display unit width. */ public Surface drawLine (float x0, float y0, float x1, float y1, float width) { // swap the line end points if x1 is less than x0 if (x1 < x0) { float temp = x0; x0 = x1; x1 = temp; temp = y0; y0 = y1; y1 = temp; } float dx = x1 - x0, dy = y1 - y0; float length = FloatMath.sqrt(dx * dx + dy * dy); float wx = dx * (width / 2) / length; float wy = dy * (width / 2) / length; AffineTransform xf = new AffineTransform(); xf.setRotation(FloatMath.atan2(dy, dx)); xf.setTranslation(x0 + wy, y0 - wx); Transforms.multiply(tx(), xf, xf); if (patternTex != null) { batch.addQuad(patternTex, tint, xf, 0, 0, length, width); } else { batch.addQuad(colorTex, Tint.combine(fillColor, tint), xf, 0, 0, length, width); } return this; }
@Override // from RectangularShape public boolean contains (float px, float py) { // normalize point float nx = (px - x()) / width() - 0.5f; float ny = (py - y()) / height() - 0.5f; if ((nx * nx + ny * ny) > 0.25) { return false; } float extent = angleExtent(); float absExtent = Math.abs(extent); if (absExtent >= 360f) { return true; } boolean containsAngle = containsAngle(FloatMath.toDegrees(-FloatMath.atan2(ny, nx))); if (arcType() == PIE) { return containsAngle; } if (absExtent <= 180f && !containsAngle) { return false; } Line l = new Line(startPoint(), endPoint()); int ccw1 = l.relativeCCW(px, py); int ccw2 = l.relativeCCW(centerX(), centerY()); return ccw1 == 0 || ccw2 == 0 || ((ccw1 + ccw2) == 0 ^ absExtent > 180f); }
@Override // from RectangularShape public boolean contains (float px, float py) { // normalize point float nx = (px - x()) / width() - 0.5f; float ny = (py - y()) / height() - 0.5f; if ((nx * nx + ny * ny) > 0.25) { return false; } float extent = angleExtent(); float absExtent = Math.abs(extent); if (absExtent >= 360f) { return true; } boolean containsAngle = containsAngle(FloatMath.toDegrees(-FloatMath.atan2(ny, nx))); if (arcType() == PIE) { return containsAngle; } if (absExtent <= 180f && !containsAngle) { return false; } Line l = new Line(startPoint(), endPoint()); int ccw1 = l.relativeCCW(px, py); int ccw2 = l.relativeCCW(centerX(), centerY()); return ccw1 == 0 || ccw2 == 0 || ((ccw1 + ccw2) == 0 ^ absExtent > 180f); }