jv.vecmath

## Class PuVectorGeom

• java.lang.Object
• jv.vecmath.PuVectorGeom

• ```public class PuVectorGeom
extends java.lang.Object```
Static methods for vector geometry. Most methods work in euclidean vector spaces of arbitrary dimension.
• ### Constructor Summary

Constructors
Constructor and Description
`PuVectorGeom()`
• ### Method Summary

Methods
Modifier and Type Method and Description
`static boolean` ```circleThruPoints(PdVector center, double radius, PdVector p, PdVector q, PdVector r)```
Compute circle through three given points.
`static void` ```ctg(double[] ctg, PdVector p, PdVector q, PdVector r)```
Compute cotangent of the vertex angles at all vertices of the triangle (p, q, r).
`static double` ```ctg(PdVector p, PdVector q1, PdVector q2)```
Compute cotangent of the vertex angle at vertex p in the triangle (p, q1, q2).
`static double` ```distOfLineToLine(PdVector base1, PdVector dir1, PdVector base2, PdVector dir2)```
Compute distance of line to line.
`static double` ```distOfPointToLine(PdVector p, PdVector base, PdVector dir)```
Compute distance of point to line.
`static double` ```distOfPointToPlane(PdVector p, PdVector base, PdVector normal)```
Compute distance of point to plane.
`static double` ```distVectorOfLineToLine(PdVector lot, PdVector base1, PdVector dir1, PdVector base2, PdVector dir2)```
Compute shortest distance vector of line to line.
`static void` ```distVectorOfPointToLine(PdVector lot, PdVector p, PdVector base, PdVector dir)```
Compute shortest distance vector of point to line.
`static void` ```distVectorOfPointToPlane(PdVector lot, PdVector p, PdVector base, PdVector normal)```
Compute shortest distance vector of point to plane.
`static boolean` ```evalCircle(PdVector p, PdVector mid, PdVector orient, PdVector start, PdVector end, double t)```
Compute a point between the two end points of a circle segment.
`static boolean` ```evalHelix(PdVector p, PdVector axisBot, PdVector axisDir, PdVector start, PdVector end, double t)```
Compute a point between the two end points of a segment of a helix.
`static double[]` ```frameToStandardFrame(PdVector first, PdVector second, PdVector third)```
Computes the necessary rotations around the y, x and z axis, to transform a given orthonormal frame into the standard basis of R^3.
`static double` ```intersectionOfLineAndLine(PdVector p, PdVector base1, PdVector dir1, PdVector base2, PdVector dir2)```
Check for intersection of line and line by solving equation `b1+sd1 = b2+td2`.
`static double` ```intersectionOfLineAndPlane(PdVector p, PdVector base1, PdVector dir, PdVector base2, PdVector normal)```
Compute intersection line and plane.
`static boolean` ```intersectionOfPlaneAndPlane(PdVector lineBase, PdVector lineDir, PdVector base1, PdVector normal1, PdVector base2, PdVector normal2)```
Compute intersection of plane and plane, and return the intersection line.
`static void` ```projectOntoLine(PdVector v, PdVector dir)```
Project a given vector to a line through the origin.
`static void` ```projectOntoLine(PdVector vProj, PdVector v, PdVector dir)```
Project a given vector to a line through the origin.
`static void` ```projectOntoPlane(PdVector v, PdVector normal)```
Project a given vector to a plane through the origin.
`static void` ```projectOntoPlane(PdVector vProj, PdVector v, PdVector normal)```
Project a given vector to a plane through the origin.
`static void` ```projectPointToCircle(PdVector proj, PdVector p, PdVector mid, PdVector normal, double radius)```
Project 3d-point onto circle in 3d by 1) project point onto plane of circle 2) adjust distance to mid point.
`static void` ```projectPointToLine(PdVector proj, PdVector p, PdVector base, PdVector dir)```
Project a given point to line.
`static void` ```projectPointToPlane(PdVector proj, PdVector p, PdVector base, PdVector normal)```
Project a given point to plane.
`static boolean` ```rotatePointAroundLine(PdVector pRot, PdVector p, PdVector axisBase, PdVector axisDir, double alpha)```
Rotate a point around an arbitrary axis by a given angle.
`static boolean` ```rotatePointAroundVector(PdVector pRot, PdVector p, PdVector axisDir, double alpha)```
Rotate a point around an axis through the origin by a given angle.
`static double` ```sphericalAngle(PdVector p, PdVector q1, PdVector q2)```
Compute spherical angle at vertex p or a triangle on the unit sphere in S^n.
`static double` ```sphericalArea(PdVector p, PdVector q, PdVector r)```
Compute area of a spherical triangle on the unit sphere in S^n.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### PuVectorGeom

`public PuVectorGeom()`
• ### Method Detail

• #### intersectionOfLineAndLine

```public static double intersectionOfLineAndLine(PdVector p,
PdVector base1,
PdVector dir1,
PdVector base2,
PdVector dir2)```
Check for intersection of line and line by solving equation `b1+sd1 = b2+td2`. Multiply both sides with d1 and with d2 to obtain two scalar equations
```    + s =  + t
+ s =  + t
=> s = d2>/(1.-**2)
```
Method works in euclidean vector spaces of arbitrary dimension.
Parameters:
`p` - computed intersection point
`base1` - any point on the first line
`dir1` - unit direction of first line
`base2` - any point on the second line
`dir2` - unit direction of second line
Returns:
double distance `s` from base1 to intersection point, or Double.MAX_VALUE if line and plane are parallel.
• #### intersectionOfLineAndPlane

```public static double intersectionOfLineAndPlane(PdVector p,
PdVector base1,
PdVector dir,
PdVector base2,
PdVector normal)```
Compute intersection line and plane. Line is given by base point and direction, plane is given by base point and plane normal. The intersection point x=ray+s*dir on the line must fulfill plane equation ` = `. Use this equation to derive a value for `s` by solving ` = ` leading to `s = /`. Direction of ray must be normalized, normal of plane need not be normalized.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`p` - computed intersection point
`base1` - any point on the line
`dir` - unit direction of line
`base2` - any point on the plane
`normal` - normal of plane, need not be normalized
Returns:
double distance `s` from base1 to intersection point, or Double.MAX_VALUE if line and plane are parallel.
• #### intersectionOfPlaneAndPlane

```public static boolean intersectionOfPlaneAndPlane(PdVector lineBase,
PdVector lineDir,
PdVector base1,
PdVector normal1,
PdVector base2,
PdVector normal2)```
Compute intersection of plane and plane, and return the intersection line.

```   lineDir parallel to n1xn2
lineBase = s*n1 + t*n2.
```
Insert in both plane equations and solve for s and t:
```    =
=
s + t =
s + t =
=> s = (-)/(1.-**2)
=> t = (-)/(1.-**2)
```
Method only works in euclidean 3-space.
Parameters:
`lineBase` - computed point on the intersection line
`lineDir` - computed direction of the intersection line
`base1` - base point of plane1
`base2` - base point of plane2
`normal1` - unit normal of plane1
`normal2` - unit normal of plane2
Returns:
`true` if both planes intersect
• #### distVectorOfPointToLine

```public static void distVectorOfPointToLine(PdVector lot,
PdVector p,
PdVector base,
PdVector dir)```
Compute shortest distance vector of point to line.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`lot` - resulting distance vector
`p` - given point
`base` - some point of the line
`dir` - unit direction of the line
`projectPointToLine(jv.vecmath.PdVector, jv.vecmath.PdVector, jv.vecmath.PdVector, jv.vecmath.PdVector)`
• #### distVectorOfPointToPlane

```public static void distVectorOfPointToPlane(PdVector lot,
PdVector p,
PdVector base,
PdVector normal)```
Compute shortest distance vector of point to plane.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`lot` - resulting distance vector
`p` - given point
`base` - some point on the plane
`normal` - unit normal of plane
`projectPointToPlane(jv.vecmath.PdVector, jv.vecmath.PdVector, jv.vecmath.PdVector, jv.vecmath.PdVector)`
• #### distVectorOfLineToLine

```public static double distVectorOfLineToLine(PdVector lot,
PdVector base1,
PdVector dir1,
PdVector base2,
PdVector dir2)```
Compute shortest distance vector of line to line. Method only works in euclidean 3-spaces.
Parameters:
`lot` - resulting distance vector
`base1` - base point of line1
`base2` - base point of line2
`dir1` - direction of line1
`dir2` - direction of line2
Returns:
distance of both lines, or Double.MAX_VALUE if parallel.
`distOfLineToLine(jv.vecmath.PdVector, jv.vecmath.PdVector, jv.vecmath.PdVector, jv.vecmath.PdVector)`
• #### distOfPointToLine

```public static double distOfPointToLine(PdVector p,
PdVector base,
PdVector dir)```
Compute distance of point to line. Use formula `dist = |(p-base) x dir|`.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`p` - given point
`base` - some point of the line
`dir` - direction of the line with unit length 1.
Returns:
distance of point to line, or Double.MAX_VALUE if line direction not normalized.
• #### distOfPointToPlane

```public static double distOfPointToPlane(PdVector p,
PdVector base,
PdVector normal)```
Compute distance of point to plane. Use formula `dist = `, that means, we use the signed distance which is positive if p lies in direction of the normal.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`p` - given point
`base` - some point of the line
`normal` - unit normal of plane with length 1.
Returns:
distance signed distance is positive if p is in direction of normal
• #### distOfLineToLine

```public static double distOfLineToLine(PdVector base1,
PdVector dir1,
PdVector base2,
PdVector dir2)```
Compute distance of line to line. Use formula `dist = ||/|dir1xdir2|`. Special care is taken if directions are degenerate.

Currently, method works in Euclidean 3-space only.

Parameters:
`base1` - base point of line1
`base2` - base point of line2
`dir1` - direction of line1
`dir2` - direction of line2
Returns:
distance
• #### projectPointToLine

```public static void projectPointToLine(PdVector proj,
PdVector p,
PdVector base,
PdVector dir)```
Project a given point to line. Use formula `proj = base + dir`. Point and projected point may be the same vector instances.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`proj` - projection of p to the line
`p` - given point
`base` - some point of the line
`dir` - unit direction of the line
• #### projectPointToPlane

```public static void projectPointToPlane(PdVector proj,
PdVector p,
PdVector base,
PdVector normal)```
Project a given point to plane. Use formula `p - normal`. Point and projected point may be the same vector instances.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`proj` - projection of p to the line
`p` - given point
`base` - some point of the plane
`normal` - unit normal of plane
• #### projectPointToCircle

```public static void projectPointToCircle(PdVector proj,
PdVector p,
PdVector mid,
PdVector normal,
Project 3d-point onto circle in 3d by 1) project point onto plane of circle 2) adjust distance to mid point. Point and projected point may be the same vector instances.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`proj` - projection of p to the line
`p` - given point
`mid` - some point of the plane
`normal` - unit normal of plane
• #### projectOntoLine

```public static void projectOntoLine(PdVector v,
PdVector dir)```
Project a given vector to a line through the origin. Use formula `v = dir/|dir|^2`.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`v` - given vector, also contains the result
`dir` - unit direction of the line
• #### projectOntoLine

```public static void projectOntoLine(PdVector vProj,
PdVector v,
PdVector dir)```
Project a given vector to a line through the origin. Use formula `vProj = dir/|dir|^2`. Vector and projected vector may be the same vector instances.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`vProj` - projection of v to the line through the origin
`v` - given vector
`dir` - unit direction of the line
• #### projectOntoPlane

```public static void projectOntoPlane(PdVector v,
PdVector normal)```
Project a given vector to a plane through the origin. Use formula `v = v-normal/|normal|^2`.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`v` - given vector, also contains the result
`normal` - unit normal of the plane
• #### projectOntoPlane

```public static void projectOntoPlane(PdVector vProj,
PdVector v,
PdVector normal)```
Project a given vector to a plane through the origin. Use formula `vProj = v-normal/|normal|^2`. Vector and projected vector may be the same vector instances.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`vProj` - projection of v to the plane through the origin
`v` - given vector
`normal` - unit normal of the plane
• #### circleThruPoints

```public static boolean circleThruPoints(PdVector center,
PdVector p,
PdVector q,
PdVector r)```
Compute circle through three given points. Use formula `dist = ||/|dir1xdir2|`.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`center` - resulting center of circle
`radius` - resulting radius of circle
`p` - given point
`q` - given point
`r` - given point
Returns:
`true` if circle could be computed.
• #### evalCircle

```public static boolean evalCircle(PdVector p,
PdVector mid,
PdVector orient,
PdVector start,
PdVector end,
double t)```
Compute a point between the two end points of a circle segment. The three points mid, start and end determine the plane of the circle. The vector orient determines the orientation of the circle segment from start to end, i.e. how to run around the circle. The value t specifies the relative position on the segment, t=0 corresponds to start and t=1 corresponds to end.

Method only works in euclidean 3-space.

Parameters:
`p` - calculated point on circle segment
`mid` - center of circle
`orient` - normal vector determines which angle to take
`start` - first point on circle segment
`end` - second point on circle segment
`t` - relative position in [0.,1.] between start and end on segment
Returns:
`true` if circle could be evaluated.
`PdVector.angleWithOrientation(PdVector, PdVector, PdVector)`, `rotatePointAroundLine(PdVector, PdVector, PdVector, PdVector, double)`
• #### evalHelix

```public static boolean evalHelix(PdVector p,
PdVector axisBot,
PdVector axisDir,
PdVector start,
PdVector end,
double t)```
Compute a point between the two end points of a segment of a helix. The point axisBot and direction axisDir determine an axis which generates a helix when rotating and translating the point start around the axis to the point end. The value t specifies the relative position on the segment, t=0 corresponds to start and t=1 corresponds to end.

Method only works in euclidean 3-space.

Parameters:
`p` - calculated point on helix segment
`axisBot` - point on axis of helix
`axisDir` - unit direction of axis of helix
`start` - first point on helix
`end` - second point on helix
`t` - relative position in [0.,1.] between start and end on segment
Returns:
`true` if helix could be evaluated.
`PdVector.angleWithOrientation(PdVector, PdVector, PdVector)`, `rotatePointAroundLine(PdVector, PdVector, PdVector, PdVector, double)`
• #### rotatePointAroundVector

```public static boolean rotatePointAroundVector(PdVector pRot,
PdVector p,
PdVector axisDir,
double alpha)```
Rotate a point around an axis through the origin by a given angle.

Method only works in euclidean 3-space.

Parameters:
`pRot` - rotated point
`p` - point to rotate. May be equal to pRot.
`axisDir` - unit direction of rotation axis through origin
`alpha` - rotation angle, in radians
Returns:
`true` if rotation could be performed.
`rotatePointAroundLine(PdVector,PdVector,PdVector,PdVector,double)`
• #### rotatePointAroundLine

```public static boolean rotatePointAroundLine(PdVector pRot,
PdVector p,
PdVector axisBase,
PdVector axisDir,
double alpha)```
Rotate a point around an arbitrary axis by a given angle. Axis need not go through the origin.

Method only works in euclidean 3-space.

Parameters:
`pRot` - rotated point
`p` - point to rotate
`axisBase` - some point on the rotation axis
`axisDir` - unit direction of rotation axis
`alpha` - rotation angle
Returns:
`true` if rotation could be performed.
`rotatePointAroundVector(PdVector,PdVector,PdVector,double)`
• #### ctg

```public static double ctg(PdVector p,
PdVector q1,
PdVector q2)```
Compute cotangent of the vertex angle at vertex p in the triangle (p, q1, q2).

Method works in Euclidean vector spaces of arbitrary dimension.

Parameters:
`p` - vertex where to compute the cotangent
`q1` - other vertex of the triangle
`q2` - other vertex of the triangle
Returns:
cotangent of vertex angle
`ctg(double[],PdVector,PdVector,PdVector)`
• #### ctg

```public static void ctg(double[] ctg,
PdVector p,
PdVector q,
PdVector r)```
Compute cotangent of the vertex angles at all vertices of the triangle (p, q, r).

Method works in Euclidean vector spaces of arbitrary dimension.

Parameters:
`ctg` - cotangent of all vertex angles
`p` - vertex of the triangle
`q` - vertex of the triangle
`r` - vertex of the triangle
`ctg(PdVector,PdVector,PdVector)`, `PuMath.ctg(double[],double,double,double)`
• #### sphericalAngle

```public static double sphericalAngle(PdVector p,
PdVector q1,
PdVector q2)```
Compute spherical angle at vertex p or a triangle on the unit sphere in S^n. All vertices must lie on a unit sphere, i.e. they must have unit length.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`p` - vertex where to compute the angle
`q1` - other vertex of the triangle
`q2` - other vertex of the triangle
Returns:
spherical vertex angle at p
`PdVector.angle(PdVector,PdVector,PdVector)`
• #### sphericalArea

```public static double sphericalArea(PdVector p,
PdVector q,
PdVector r)```
Compute area of a spherical triangle on the unit sphere in S^n. All vertices must lie on a unit sphere, i.e. they must have unit length.

Method works in euclidean vector spaces of arbitrary dimension.

Parameters:
`p` - vertex of the triangle
`q` - vertex of the triangle
`r` - vertex of the triangle
Returns:
area of the spherical triangle
`sphericalAngle(PdVector,PdVector,PdVector)`
• #### frameToStandardFrame

```public static double[] frameToStandardFrame(PdVector first,
PdVector second,
PdVector third)```
Computes the necessary rotations around the y, x and z axis, to transform a given orthonormal frame into the standard basis of R^3. The first vector of the frame is mapped to the x-axis, the second to the y-axis and so on.

So if you want to get these rotation angles for e.g. the camera position, then you should call this method with normalized first = viewdir x upvector, second = upvector and third = -viewdir.

Parameters:
`first` - First vector of frame -> x-axis. FRAME MUST BE ORTHONORMAL! Orthonormality is not checked by this method!
`second` - Second vector of frame -> y-axis. See first.
`third` - Third vector of frame -> z-axis. See first.
Returns:
Array of angles (RAD): angle to rotate around y-axis, around x-axis and around z-axis in this order.