本文整理了Java中pythagoras.f.Vector
类的一些代码示例,展示了Vector
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector
类的具体详情如下:
包路径:pythagoras.f.Vector
类名称:Vector
[英]Represents a vector in a plane.
[中]表示平面中的向量。
代码示例来源:origin: com.samskivert/pythagoras
/**
* Transforms a vector as specified, storing the result in the vector provided.
* @return a reference to the result vector, for chaining.
*/
public static Vector transform (float x, float y, float sx, float sy, float sina, float cosa,
Vector result) {
return result.set((x*cosa - y*sina) * sx, (x*sina + y*cosa) * sy);
}
代码示例来源:origin: com.samskivert/pythagoras
@Override // from interface IVector
public Vector clone () {
return new Vector(this);
}
代码示例来源:origin: com.samskivert/pythagoras
/**
* Sets this vector's magnitude, preserving its angle.
*/
public Vector setLength (float length) {
return normalizeLocal().scaleLocal(length);
}
代码示例来源:origin: com.samskivert/pythagoras
@Override // from IRay2
public Vector getNearestPoint (IVector point, Vector result) {
if (result == null) {
result = new Vector();
}
float r = point.subtract(origin).dot(direction);
result.set(origin.add(direction.scale(r)));
return result;
}
代码示例来源:origin: threerings/playn
protected void onMove(float x, float y) {
Vector delta = new Vector(x, y).subtractLocal(_pstart);
layer.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y);
}
代码示例来源:origin: com.samskivert/pythagoras
@Override // from IRay2
public boolean getIntersection (IVector center, float radius, Vector result) {
// see if we start inside the circle
if (origin.distanceSq(center) <= radius*radius) {
result.set(origin);
return true;
}
// then if we intersect the circle
float ax = origin.x - center.x(), ay = origin.y - center.y();
float b = 2f*(direction.x*ax + direction.y*ay);
float c = ax*ax + ay*ay - radius*radius;
float radicand = b*b - 4f*c;
if (radicand < 0f) {
return false;
}
float t = (-b - FloatMath.sqrt(radicand)) * 0.5f;
boolean isect = (t >= 0f);
if (isect) {
origin.addScaled(direction, t, result);
}
return isect;
}
代码示例来源:origin: com.samskivert/pythagoras
/**
* Sets this vector's angle, preserving its magnitude.
* @return a reference to this vector, for chaining.
*/
public Vector setAngle (float angle) {
float l = length();
return set(l * FloatMath.cos(angle), l * FloatMath.sin(angle));
}
代码示例来源:origin: threerings/tripleplay
@Override protected void update (Clock clock, Entities entities) {
Point p = _pos;
Vector v = _vel;
int delta = clock.dt;
for (int ii = 0, ll = entities.size(); ii < ll; ii++) {
int eid = entities.get(ii);
pos.get(eid, p); // get our current pos
p.x = wrapx(p.x); // wrap it around the screen if necessary
p.y = wrapy(p.y);
opos.set(eid, p); // copy wrapped pos to opos
vel.get(eid, v).scaleLocal(delta); // turn velocity into delta pos
pos.set(eid, p.x + v.x, p.y + v.y); // add velocity (but don't wrap)
}
}
代码示例来源:origin: com.samskivert/pythagoras
/** Adds a scaled vector in-place to this one.
* @return a reference to this vector, for chaining. */
public Vector addScaledLocal (IVector other, float v) {
return addScaled(other, v, this);
}
代码示例来源:origin: com.samskivert/pythagoras
/** Adds a vector in-place to this one.
* @return a reference to this vector, for chaining. */
public Vector addLocal (IVector other) {
return add(other, this);
}
代码示例来源:origin: samskivert/pythagoras
@Override // from IRay2
public Vector getNearestPoint (IVector point, Vector result) {
if (result == null) {
result = new Vector();
}
float r = point.subtract(origin).dot(direction);
result.set(origin.add(direction.scale(r)));
return result;
}
代码示例来源:origin: playn/playn
protected void doMove(float x, float y) {
Vector delta = new Vector(x, y).subtractLocal(_pstart);
layer.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y);
}
代码示例来源:origin: samskivert/pythagoras
@Override // from IRay2
public boolean getIntersection (IVector center, float radius, Vector result) {
// see if we start inside the circle
if (origin.distanceSq(center) <= radius*radius) {
result.set(origin);
return true;
}
// then if we intersect the circle
float ax = origin.x - center.x(), ay = origin.y - center.y();
float b = 2f*(direction.x*ax + direction.y*ay);
float c = ax*ax + ay*ay - radius*radius;
float radicand = b*b - 4f*c;
if (radicand < 0f) {
return false;
}
float t = (-b - FloatMath.sqrt(radicand)) * 0.5f;
boolean isect = (t >= 0f);
if (isect) {
origin.addScaled(direction, t, result);
}
return isect;
}
代码示例来源:origin: samskivert/pythagoras
/**
* Sets this vector's angle, preserving its magnitude.
* @return a reference to this vector, for chaining.
*/
public Vector setAngle (float angle) {
float l = length();
return set(l * FloatMath.cos(angle), l * FloatMath.sin(angle));
}
代码示例来源:origin: samskivert/pythagoras
/** Adds a scaled vector in-place to this one.
* @return a reference to this vector, for chaining. */
public Vector addScaledLocal (IVector other, float v) {
return addScaled(other, v, this);
}
代码示例来源:origin: com.samskivert/pythagoras
/** Adds a vector in-place to this one.
* @return a reference to this vector, for chaining. */
public Vector addLocal (float x, float y) {
return add(x, y, this);
}
代码示例来源:origin: com.samskivert/pythagoras
/** Transforms a vector as specified (as a point, accounting for translation), storing the
* result in the vector provided.
* @return a reference to the result vector, for chaining. */
public static Vector transform (float x, float y, float sx, float sy, float sina, float cosa,
float tx, float ty, Vector result) {
return result.set((x*cosa - y*sina) * sx + tx, (x*sina + y*cosa) * sy + ty);
}
代码示例来源:origin: com.samskivert/pythagoras
@Override // from interface IVector
public Vector negate () {
return negate(new Vector());
}
代码示例来源:origin: threerings/playn
@Override
public void onMouseDrag(MotionEvent event) {
Vector delta = new Vector(event.x(), event.y()).subtractLocal(_pstart);
label.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y);
modify(event);
motionLabel.set("mouse drag", describe(event, ""));
}
@Override
代码示例来源:origin: samskivert/pythagoras
/**
* Sets this vector's magnitude, preserving its angle.
*/
public Vector setLength (float length) {
return normalizeLocal().scaleLocal(length);
}
内容来源于网络,如有侵权,请联系作者删除!