|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcz.cuni.jagrlib.Geometry
public class Geometry
Simple geometric routines.
| Field Summary | |
|---|---|
static double |
EPSILON
The smallest absolute value that can be inverted. |
static float |
EPSILON_F
The smallest absolute value that can be inverted. |
static double |
SCENE_EPSILON
Upper bound for 3D rounding errors (two 3D points closer than SCENE_EPSILON
are assumed to be equal). |
| Constructor Summary | |
|---|---|
Geometry()
|
|
| Method Summary | |
|---|---|
static double |
dotProduct3D(double[] a,
double[] b)
Computes dot product of two 3D vectors. |
static void |
getAxes(double[] p,
double[] p1,
double[] p2)
Finds two other axes to the given vector, their vector product will give the original vector, all three vectors will be perpendicular to each other. |
static void |
getPerpendiculars(double[] p,
double[] p1,
double[] p2)
Finds two vectors perpendicular to the given vector (so that their vector product will give the original vector). |
static boolean |
isZero(double x)
Compares the given number with zero (using EPSILON tolerance). |
static boolean |
isZero(float x)
Compares the given number with zero (using EPSILON_F tolerance). |
static double |
normalize3D(double[] v)
Normalizes the given 3D vector (Cartesian or homogeneous) in place. |
static double[] |
normalize3D(double[] from,
double[] to)
Normalizes the given 3D vector (Cartesian or homogeneous) and assigns it. |
static double |
pointBox2D(double[] p,
double[] ul,
double[] size)
Computes 2D distance between point p and the rectangular box ul, ul+size. |
static double |
pointBox3D(double[] p,
double[] ul,
double[] size)
Computes 3D distance between point p and the rectangular box ul, ul+size. |
static double[] |
pointInTriangle2D(double[] p,
double[] a,
double[] b,
double[] c,
double[] uv)
Tests whether the given point lies in the given triangle. |
static double |
pointPoint3D(double[] a,
double[] b)
Computes Euclidean distance of two 3D points. |
static double |
pointSegment2D(double[] p,
double[] a,
double[] b)
Computes 2D distance between point p and line segment ab. |
static double |
pointSegment2D(double px,
double py,
double ax,
double ay,
double bx,
double by)
Computes 2D distance between point [ px, py ] and line segment
[ ax, ay ] [ bx, by ]. |
static double |
pointSegment3D(double[] p,
double[] a,
double[] b)
Computes 3D distance between point p and the line segment ab. |
static boolean |
rayBox(double[] origin,
double[] direction,
double[] ul,
double[] size,
double[] result)
Computes intersection of the ray with the given AABB (works in either dimension). |
static double |
raySegment2D(double[] origin,
double[] direction,
double[] a,
double[] b)
Computes intersection of the given ray with the given line segment. |
static double |
raySegment2D(double ox,
double oy,
double dx,
double dy,
double ax,
double ay,
double bx,
double by)
Computes intersection of the given ray with the given line segment. |
static double |
rayTriangle3D(double[] origin,
double[] direction,
double[] a,
double[] b,
double[] c,
double[] uv)
Ray-triangle intersection test in 3D. |
static double[] |
specularReflection(double[] normal,
double[] in,
double[] out)
Computes direction vector of perfect specular-reflected ray. |
static double[] |
specularRefraction(double[] normal,
double n,
double[] in,
double[] out)
Computes direction vector of perfect specular-refracted ray. |
static double[] |
toCartesian(double sinTheta,
double cosTheta,
double phi,
double[] result)
Converts spherical coordinate vector to Cartesian 3D coordinates. |
static double[] |
toCartesian(double x,
double y,
double z,
double w,
double[] to)
Converts the given coordinate vector to Cartesian 3D coordinates. |
static double[] |
toCartesian3D(double[] from,
double[] to)
Converts the given coordinate vector to Cartesian 3D coordinates. |
static double |
triangleArea(double[][] v)
Computes area of the given triangle. |
static double[] |
triangleNormal(double[][] v,
double[] normal)
Computes normal vector of the given triangle. |
static double[] |
vector(double[] a,
double[] b,
double[] result)
Computes a vector from its endpoints. |
static double[] |
vectorProduct(double[] a,
double[] b,
double[] result)
Computes vector product of two (either cartesian or homogeneous) 3D vectors. |
static java.lang.String |
vectorToString(double[] v)
Converts double[] vector to readable form. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final double EPSILON
public static final float EPSILON_F
public static final double SCENE_EPSILON
SCENE_EPSILON
are assumed to be equal).
| Constructor Detail |
|---|
public Geometry()
| Method Detail |
|---|
public static final boolean isZero(double x)
EPSILON tolerance).
public static final boolean isZero(float x)
EPSILON_F tolerance).
public static final double pointPoint3D(double[] a,
double[] b)
a - The 1st point.b - The 2nd point.
Double.POSITIVE_INFINITY in case of error).
public static final double pointSegment2D(double[] p,
double[] a,
double[] b)
p and line segment ab.
p - Point coordinates.a - Segment's starting point.b - Segment's end point.
Double.POSITIVE_INFINITY in case of error.
public static final double pointSegment2D(double px,
double py,
double ax,
double ay,
double bx,
double by)
[ px, py ] and line segment
[ ax, ay ] [ bx, by ].
public static final double pointSegment3D(double[] p,
double[] a,
double[] b)
p and the line segment ab.
p - Point coordinates.a - Segment's starting point.b - Segment's end point.
Double.POSITIVE_INFINITY in case of error.
public static final double pointBox2D(double[] p,
double[] ul,
double[] size)
p and the rectangular box ul, ul+size.
p - Point coordinates.ul - Upper left rectangle corner.size - Box size.
-1.0 if the point lies inside the rectangle.
public static final double pointBox3D(double[] p,
double[] ul,
double[] size)
p and the rectangular box ul, ul+size.
p - Point coordinates.ul - Upper left box corner.size - Box size.
-1.0 if the point lies inside the box.
public static final double raySegment2D(double[] origin,
double[] direction,
double[] a,
double[] b)
t < 0.0).
Returns Parametric coordinate on the ray if succeeded, Double.NEGATIVE_INFINITY otherwise.
public static final double raySegment2D(double ox,
double oy,
double dx,
double dy,
double ax,
double ay,
double bx,
double by)
t < 0.0).
Returns Parametric coordinate on the ray if succeeded, Double.NEGATIVE_INFINITY otherwise.
public static final boolean rayBox(double[] origin,
double[] direction,
double[] ul,
double[] size,
double[] result)
true if intersection exists (in such case the pre-allocated result array will be
filled with [ tmin. tmax ]).
public static final double rayTriangle3D(double[] origin,
double[] direction,
double[] a,
double[] b,
double[] c,
double[] uv)
origin + t * direction = (1 - u - v) * a + u * b + v * c.
uv - Pre-allocated array to hold barycentric coordinates.
Double.NEGATIVE_INFINITY otherwise.
public static final double[] pointInTriangle2D(double[] p,
double[] a,
double[] b,
double[] c,
double[] uv)
p = (1 - u - v) * a + u * b + v * c.
p - 2D point.a - Vertex A of the triangle.b - Vertex B of the triangle.c - Vertex C of the triangle.uv - Pre-allocated array to hold barycentric coordinates.
null otherwise.
public static final double[] vector(double[] a,
double[] b,
double[] result)
a - Vector's starting point.b - Vector's end point.result - Optional pre-allocated result array (double[3] or
double[4]).
null for bad parameters, double[3] for
result == null.public static final double triangleArea(double[][] v)
public static final double[] triangleNormal(double[][] v,
double[] normal)
public static final double dotProduct3D(double[] a,
double[] b)
a - The first argument.b - The second argument.
public static final double[] vectorProduct(double[] a,
double[] b,
double[] result)
a - The first argument.b - The second argument.result - Optional pre-allocated result array (double[3] or
double[4]).
null for bad parameters, double[3] for
result == null.
public static final void getPerpendiculars(double[] p,
double[] p1,
double[] p2)
p - Inout vector (double[3] or double[4]).p1 - The 1st output vector (pre-allocated array of size 3 or
4).p2 - The 2nd output vector (pre-allocated array of size 3 or
4).vectorProduct(double[], double[], double[]),
getAxes(double[], double[], double[])
public static final void getAxes(double[] p,
double[] p1,
double[] p2)
p - Inout vector (double[3] or double[4]).p1 - The 1st output vector (pre-allocated array of size 3 or
4).p2 - The 2nd output vector (pre-allocated array of size 3 or
4).vectorProduct(double[], double[], double[]),
getPerpendiculars(double[], double[], double[])
public static final double[] specularReflection(double[] normal,
double[] in,
double[] out)
normal - Normal vector (points to the outside of the solid). double[3]
or double[4].in - Input vector (points from the intersection point to the light source).
double[3] or double[4].out - Pre-allocated array to hold result - points from the intersection point.
double[3] or double[4], can be null.
specularRefraction(double[], double, double[], double[])
public static final double[] specularRefraction(double[] normal,
double n,
double[] in,
double[] out)
normal - Normal vector (double[3] or double[4]).n - Relative index of refraction (v(normal) / v(-normal)).in - Input vector (points from the intersection point to the light source).
double[3] or double[4].out - Pre-allocated array to hold result - points from the intersection point.
double[3] or double[4], can be null.
null
in case of total reflection.specularReflection(double[], double[], double[])public static final double normalize3D(double[] v)
v - Vector to be normalized (double[3] or double[4]).
v[3] will be ignored (not changed).
public static final double[] normalize3D(double[] from,
double[] to)
from - Source coordinate vector (v[3] /if present/ will be ignored).to - Pre-allocated destination coordinate vector (double[3] or
double[4]).
double[3] for from == null) or
null in case of error.
public static final double[] toCartesian3D(double[] from,
double[] to)
from - Source coordinate vector (double[3] or double[4]).to - Pre-allocated destination coordinate vector (double[3] or
null).
null in case of error.toCartesian(double, double, double, double, double[])
public static final double[] toCartesian(double x,
double y,
double z,
double w,
double[] to)
x - X coordinate.y - Y coordinate.z - Z coordinate.w - W coordinate.to - Pre-allocated destination coordinate vector (double[3] or
null).
toCartesian3D(double[], double[])
public static final double[] toCartesian(double sinTheta,
double cosTheta,
double phi,
double[] result)
sinTheta - Sinus of angle theta.cosTheta - Cosinus of angle theta.phi - Angle phi.result - Pre-allocated destination coordinate vector
(double[3] or null).
toCartesian3D(double[], double[])public static final java.lang.String vectorToString(double[] v)
double[] vector to readable form.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||