public class

Geometry

extends Object
java.lang.Object
   ↳ sofia.graphics.Geometry

Class Overview

This class contains various geometry-related static helper methods.

Summary

Public Methods
static float angleBetween(PointF origin, PointF extent)
Returns the angle, in degrees, between the two points origin and extent.
static float angleBetween(float x1, float y1, float x2, float y2)
Returns the angle, in degrees, between the two points (x1, y1) and (x2, y2).
static PointF clone(PointF point)
Creates a copy of the specified point.
static float distanceBetween(float x1, float y1, float x2, float y2)
Calculates the distance between two points.
static float distanceBetween(PointF origin, PointF extent)
Calculates the distance between two points.
static float magnitude(PointF vector)
Calculates the magnitude of a vector given by its x- and y-coordinates.
static float magnitude(float x, float y)
Calculates the magnitude of a vector given by its x- and y-coordinates.
static PointF midpoint(float x1, float y1, float x2, float y2)
Computes the midpoint between two points.
static PointF midpoint(PointF p1, PointF p2)
Computes the midpoint between two points.
static PointF polarShift(PointF origin, float angle, float distance)
Calculates the translation of a point based on the specified angle and distance.
static String toString(RectF rect)
Converts a rectangle to a string of the form "(left, top)-(right, bottom)".
static String toString(PointF point)
Converts a point to a string of the form "(x, y)".
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static float angleBetween (PointF origin, PointF extent)

Returns the angle, in degrees, between the two points origin and extent. Angles increase clockwise since y-coordinates increase in the downward direction; this is the opposite of a standard Cartesian coordinate system. The returned angle will be between -180 and 180 degrees.

Parameters
origin the first point (the origin)
extent the other point
Returns
  • the angle between origin and extent, in degrees clockwise, between -180 and 180

public static float angleBetween (float x1, float y1, float x2, float y2)

Returns the angle, in degrees, between the two points (x1, y1) and (x2, y2). Angles increase clockwise since y-coordinates increase in the downward direction; this is the opposite of a standard Cartesian coordinate system. The returned angle will be between -180 and 180 degrees.

Parameters
x1 the x-coordinate of the first point (the origin)
y1 the y-coordinate of the first point (the origin)
x2 the x-coordinate of the other point
y2 the y-coordinate of the other point
Returns
  • the angle between (x1, y1) and (x2, y2), in degrees clockwise, between -180 and 180

public static PointF clone (PointF point)

Creates a copy of the specified point.

Parameters
point the point to copy
Returns
  • a new point with the same coordinates as the original

public static float distanceBetween (float x1, float y1, float x2, float y2)

Calculates the distance between two points.

Parameters
x1 the x-coordinate of the origin
y1 the y-coordinate of the origin
x2 the x-coordinate of the extent
y2 the y-coordinate of the extent
Returns
  • the distance between (x1, y1) and (x2, y2)

public static float distanceBetween (PointF origin, PointF extent)

Calculates the distance between two points.

Parameters
origin the first point
extent the second point
Returns
  • the distance between origin and extent

public static float magnitude (PointF vector)

Calculates the magnitude of a vector given by its x- and y-coordinates.

Parameters
vector the vector
Returns
  • the magnitude of the vector (x, y)

public static float magnitude (float x, float y)

Calculates the magnitude of a vector given by its x- and y-coordinates.

Parameters
x the x-coordinate of the vector
y the y-coordinate of the vector
Returns
  • the magnitude of the vector (x, y)

public static PointF midpoint (float x1, float y1, float x2, float y2)

Computes the midpoint between two points.

Parameters
x1 the x-coordinate of the first point
y1 the y-coordinate of the first point
x2 the x-coordinate of the second point
y2 the y-coordinate of the second point
Returns
  • the midpoint of the two points

public static PointF midpoint (PointF p1, PointF p2)

Computes the midpoint between two points.

Parameters
p1 the first point
p2 the second point
Returns
  • the midpoint of the two points

public static PointF polarShift (PointF origin, float angle, float distance)

Calculates the translation of a point based on the specified angle and distance.

Parameters
origin the point to be translated
angle the angle by which to move the point, in degrees clockwise
distance the distance to move the point
Returns
  • the translated point

public static String toString (RectF rect)

Converts a rectangle to a string of the form "(left, top)-(right, bottom)". This method mainly just exists for symmetry with the one for PointF above.

Parameters
rect the rectangle
Returns
  • a string of the form "(left, top)-(right, bottom)"

public static String toString (PointF point)

Converts a point to a string of the form "(x, y)". This method is necessary because the Android PointF class does not override toString in a meaningful way.

Parameters
point the point
Returns
  • a string of the form "(x, y)"