/** Returns the distance between the given segment and point. */ public static float distanceSegmentPoint (Vector2 start, Vector2 end, Vector2 point) { return nearestSegmentPoint(start, end, point, v2tmp).dst(point); }
/** Returns the distance between the given segment and point. */ public static float distanceSegmentPoint (float startX, float startY, float endX, float endY, float pointX, float pointY) { return nearestSegmentPoint(startX, startY, endX, endY, pointX, pointY, v2tmp).dst(pointX, pointY); }
/** Returns the distance between the given segment and point. */ public static float distanceSegmentPoint (Vector2 start, Vector2 end, Vector2 point) { return nearestSegmentPoint(start, end, point, v2tmp).dst(point); }
/** Returns the distance between the given segment and point. */ public static float distanceSegmentPoint (float startX, float startY, float endX, float endY, float pointX, float pointY) { return nearestSegmentPoint(startX, startY, endX, endY, pointX, pointY, v2tmp).dst(pointX, pointY); }
/** Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ public void initialize (Body bodyA, Body bodyB, Vector2 groundAnchorA, Vector2 groundAnchorB, Vector2 anchorA, Vector2 anchorB, float ratio) { this.bodyA = bodyA; this.bodyB = bodyB; this.groundAnchorA.set(groundAnchorA); this.groundAnchorB.set(groundAnchorB); this.localAnchorA.set(bodyA.getLocalPoint(anchorA)); this.localAnchorB.set(bodyB.getLocalPoint(anchorB)); lengthA = anchorA.dst(groundAnchorA); lengthB = anchorB.dst(groundAnchorB); this.ratio = ratio; float C = lengthA + ratio * lengthB; }
/** Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. */ public void initialize (Body bodyA, Body bodyB, Vector2 groundAnchorA, Vector2 groundAnchorB, Vector2 anchorA, Vector2 anchorB, float ratio) { this.bodyA = bodyA; this.bodyB = bodyB; this.groundAnchorA.set(groundAnchorA); this.groundAnchorB.set(groundAnchorB); this.localAnchorA.set(bodyA.getLocalPoint(anchorA)); this.localAnchorB.set(bodyB.getLocalPoint(anchorB)); lengthA = anchorA.dst(groundAnchorA); lengthB = anchorB.dst(groundAnchorB); this.ratio = ratio; float C = lengthA + ratio * lengthB; }
/** Initialize the bodies, anchors, and length using the world anchors. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB) { this.bodyA = bodyA; this.bodyB = bodyB; this.localAnchorA.set(bodyA.getLocalPoint(anchorA)); this.localAnchorB.set(bodyB.getLocalPoint(anchorB)); this.length = anchorA.dst(anchorB); }
/** Initialize the bodies, anchors, and length using the world anchors. */ public void initialize (Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB) { this.bodyA = bodyA; this.bodyB = bodyB; this.localAnchorA.set(bodyA.getLocalPoint(anchorA)); this.localAnchorB.set(bodyB.getLocalPoint(anchorB)); this.length = anchorA.dst(anchorB); }
public boolean touchDragged (float x, float y, int pointer) { if (pointer > 1) return false; if (longPressFired) return false; if (pointer == 0) pointer1.set(x, y); else pointer2.set(x, y); // handle pinch zoom if (pinching) { if (listener != null) { boolean result = listener.pinch(initialPointer1, initialPointer2, pointer1, pointer2); return listener.zoom(initialPointer1.dst(initialPointer2), pointer1.dst(pointer2)) || result; } return false; } // update tracker tracker.update(x, y, Gdx.input.getCurrentEventTime()); // check if we are still tapping. if (inTapRectangle && !isWithinTapRectangle(x, y, tapRectangleCenterX, tapRectangleCenterY)) { longPressTask.cancel(); inTapRectangle = false; } // if we have left the tap square, we are panning if (!inTapRectangle) { panning = true; return listener.pan(x, y, tracker.deltaX, tracker.deltaY); } return false; }
public boolean touchDragged (float x, float y, int pointer) { if (pointer > 1) return false; if (longPressFired) return false; if (pointer == 0) pointer1.set(x, y); else pointer2.set(x, y); // handle pinch zoom if (pinching) { if (listener != null) { boolean result = listener.pinch(initialPointer1, initialPointer2, pointer1, pointer2); return listener.zoom(initialPointer1.dst(initialPointer2), pointer1.dst(pointer2)) || result; } return false; } // update tracker tracker.update(x, y, Gdx.input.getCurrentEventTime()); // check if we are still tapping. if (inTapRectangle && !isWithinTapRectangle(x, y, tapRectangleCenterX, tapRectangleCenterY)) { longPressTask.cancel(); inTapRectangle = false; } // if we have left the tap square, we are panning if (!inTapRectangle) { panning = true; return listener.pan(x, y, tracker.deltaX, tracker.deltaY); } return false; }
/** Checks whether the line segment and the circle intersect and returns by how much and in what direction the line has to move * away from the circle to not intersect. * * @param start The line segment starting point * @param end The line segment end point * @param point The center of the circle * @param radius The radius of the circle * @param displacement The displacement vector set by the method having unit length * @return The displacement or Float.POSITIVE_INFINITY if no intersection is present */ public static float intersectSegmentCircleDisplace (Vector2 start, Vector2 end, Vector2 point, float radius, Vector2 displacement) { float u = (point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y); float d = start.dst(end); u /= d * d; if (u < 0 || u > 1) return Float.POSITIVE_INFINITY; tmp.set(end.x, end.y, 0).sub(start.x, start.y, 0); tmp2.set(start.x, start.y, 0).add(tmp.scl(u)); d = tmp2.dst(point.x, point.y, 0); if (d < radius) { displacement.set(point).sub(tmp2.x, tmp2.y).nor(); return d; } else return Float.POSITIVE_INFINITY; }
/** Checks whether the line segment and the circle intersect and returns by how much and in what direction the line has to move * away from the circle to not intersect. * * @param start The line segment starting point * @param end The line segment end point * @param point The center of the circle * @param radius The radius of the circle * @param displacement The displacement vector set by the method having unit length * @return The displacement or Float.POSITIVE_INFINITY if no intersection is present */ public static float intersectSegmentCircleDisplace (Vector2 start, Vector2 end, Vector2 point, float radius, Vector2 displacement) { float u = (point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y); float d = start.dst(end); u /= d * d; if (u < 0 || u > 1) return Float.POSITIVE_INFINITY; tmp.set(end.x, end.y, 0).sub(start.x, start.y, 0); tmp2.set(start.x, start.y, 0).add(tmp.scl(u)); d = tmp2.dst(point.x, point.y, 0); if (d < radius) { displacement.set(point).sub(tmp2.x, tmp2.y).nor(); return d; } else return Float.POSITIVE_INFINITY; }
Vector2 closestVecky = null; float shortestDistance = -1; for (Vector2 vecky : map){ float veckyDist = vecky.dst(); if (closestVecky==null || veckyDist < shortestDistance){ shortestDistance = veckyDist; closestVecky = vecky; } } //when you reach here, you will have your `closestVecky` and `shortestDistance`
public static boolean deletePoint(Polygon poly, float x, float y, float tolerance) { float verts[] = poly.getTransformedVertices(); for (int i = 0; i < verts.length; i += 2) { if (Vector2.dst(x, y, verts[i], verts[i + 1]) < tolerance) { deletePoint(poly, i); return true; } } return false; }
public static float distance( final Entity a, final Entity b) { final Pos pa = (Pos)a.getComponent(Pos.class); final Pos pb = (Pos)b.getComponent(Pos.class); return tmp.set(pa.x, pa.y).dst(pb.x, pb.y); }
public float distance( final int a, final int b) { final Pos pa = pm.get(a); final Pos pb = pm.get(b); return tmp.set(pa.xy.x, pa.xy.y).dst(pb.xy.x, pb.xy.y); }
public static float distance( final Entity a, final Entity b) { final Pos pa = (Pos)a.getComponent(Pos.class); final Pos pb = (Pos)b.getComponent(Pos.class); return tmp.set(pa.xy.x, pa.xy.y).dst(pb.xy.x, pb.xy.y); }
@Override public boolean mouseMoved(int x, int y) { if (Click.FIRST == click) { // do move secondPoint.set(Engine.screenToWorld(x, y)); model.radius = worldCenter.dst(secondPoint); updateToUI(); } return super.mouseMoved(x, y); } };
@Override public void setRadius(float radius) { TMP_VECTOR1.set(vertices[0], vertices[1]); scale(radius / TMP_VECTOR1.dst(getCenterX(), getCenterY())); }
boolean hitTest(float x, float y) { if(new Vector2(this.position).add(radius, radius).dst(new Vector2(x,y))<radius){ this.stick(); return true; } if(touchDown){ this.stick(); return false; } this.unstick(); return false; }