Sofia API Reference

  • Package Index
  • Class Index
  • Packages
  • sofia.app
  • sofia.content
  • sofia.data
  • sofia.graphics
    • Interfaces
    • Joint
    • PropertyTransformer
    • Classes
    • AbstractJoint
    • Anchor
    • Color
    • CoordinateSystem
    • DirectionalPad
    • DistanceJoint
    • ElasticInInterpolator
    • ElasticInOutInterpolator
    • ElasticOutInterpolator
    • FillableShape
    • FillableShape.Animator
    • Geometry
    • Image
    • LineShape
    • MotionStep
    • OvalShape
    • PointAndAnchor
    • Polygon
    • PolygonShape
    • Predicate
    • RectangleShape
    • RevoluteJoint
    • Shape
    • Shape.Animator
    • Shape.Filter
    • ShapeField
    • ShapeFilter
    • ShapeSet
    • ShapeView
    • SizeF
    • StrokedShape
    • StrokedShape.Animator
    • TextShape
    • TextShape.Animator
    • Timings
    • ViewEdges
    • ZIndexComparator
    • Enums
    • RepeatMode
    • ShapeMotion
  • sofia.util
  • sofia.view
  • sofia.widget

public class
Geometry

extends Object

Inheritance

  • 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(PointF origin, PointF extent)
Calculates the distance between two points.
static float distanceBetween(float x1, float y1, float x2, float y2)
Calculates the distance between two points.
static PointF intersection(PointF p1, PointF p2, PointF q1, PointF q2)
Computes the point of intersection between the lines (p1, p2) and (q1, q2).
static boolean isPointOn(PointF p, PointF q1, PointF q2)
Returns true if point p is on the line formed by points q1 and q2 (in other words, all three points are collinear).
static boolean isPointToLeft(PointF p, PointF q1, PointF q2)
Returns true if point p lies to the left of the line formed by points q1 and q2.
static boolean isPointToLeftOrOn(PointF p, PointF q1, PointF q2)
Returns true if point p lies to the left of or is on the line formed by points q1 and q2.
static boolean isPointToRight(PointF p, PointF q1, PointF q2)
Returns true if point p lies to the right of the line formed by points q1 and q2.
static boolean isPointToRightOrOn(PointF p, PointF q1, PointF q2)
Returns true if point p lies to the right of or is on the line formed by points q1 and q2.
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 float perpendicularDistance(PointF p, PointF q1, PointF q2)
Computes the distance between a point and a line, measured perpendicular to that line.
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)".
Methods inherited from class java.lang.Object
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait()
final void wait(long arg0, int arg1)
final void wait(long arg0)

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 (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 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 PointF intersection (PointF p1, PointF p2, PointF q1, PointF q2)

Computes the point of intersection between the lines (p1, p2) and (q1, q2). If the lines are parallel, then this method returns null.

Parameters
p1
a point on the first line
p2
a point on the first line
q1
a point on the second line
q2
a point on the second line
Returns

the point of intersection of the two lines, or null if they are parallel

public static boolean isPointOn (PointF p, PointF q1, PointF q2)

Returns true if point p is on the line formed by points q1 and q2 (in other words, all three points are collinear).

Parameters
p
the point to test
q1
the first point on the line
q2
the second point on the line
Returns

true if the point is on the line

public static boolean isPointToLeft (PointF p, PointF q1, PointF q2)

Returns true if point p lies to the left of the line formed by points q1 and q2.

Parameters
p
the point to test
q1
the first point on the line
q2
the second point on the line
Returns

true if the point is to the left of the line

public static boolean isPointToLeftOrOn (PointF p, PointF q1, PointF q2)

Returns true if point p lies to the left of or is on the line formed by points q1 and q2.

Parameters
p
the point to test
q1
the first point on the line
q2
the second point on the line
Returns

true if the point is to the left of or on the line

public static boolean isPointToRight (PointF p, PointF q1, PointF q2)

Returns true if point p lies to the right of the line formed by points q1 and q2.

Parameters
p
the point to test
q1
the first point on the line
q2
the second point on the line
Returns

true if the point is to the right of the line

public static boolean isPointToRightOrOn (PointF p, PointF q1, PointF q2)

Returns true if point p lies to the right of or is on the line formed by points q1 and q2.

Parameters
p
the point to test
q1
the first point on the line
q2
the second point on the line
Returns

true if the point is to the right of or is on the line

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 float perpendicularDistance (PointF p, PointF q1, PointF q2)

Computes the distance between a point and a line, measured perpendicular to that line.

Parameters
p
the point whose distance from the line should be computed
q1
a point along the line
q2
another point along the line
Returns

the perpendicular distance between the point and the line

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)"