Documentation ¶
Overview ¶
Package kirv is a library of elementary curves.
Index ¶
- Constants
- Variables
- func NewArchimedeanPosTan(spec Archimedean) func(t float64) (maf.Vec2, maf.Vec2)
- func NewCirclePosTan(r float64) func(t float64) (maf.Vec2, maf.Vec2)
- func NewCycloidPosTan(r float64) func(t float64) (maf.Vec2, maf.Vec2)
- func NewEllipsePosTan(spec Ellipse) func(t float64) (maf.Vec2, maf.Vec2)
- func NewHelixPosTan(spec Helix) func(t float64) (maf.Vec, maf.Vec)
- func NewSinusoid(spec Sinusoid, decay ExpDecay) func(t float64) Parametric
- func NewSinusoidPosTan(spec Sinusoid, decay ExpDecay) func(t float64) func(x float64) (maf.Vec2, maf.Vec2)
- func NewStanding(spec Standing, decay ExpDecay) func(t float64) Parametric
- func NewStandingPosTan(spec Standing, decay ExpDecay) func(t float64) func(x float64) (maf.Vec2, maf.Vec2)
- func NewTimeDepArchimedeanPosTan(spec kinem.Archimedean) func(t float64) (maf.Vec2, maf.Vec2)
- func NewTimeDepHelixPosTan(spec kinem.Helical) func(t float64) (maf.Vec, maf.Vec)
- func NewTimeDepProjectilePosTan(spec kinem.Projectile) func(t float64) (maf.Vec2, maf.Vec2)
- func NumericalConc(car Gradienter, x float64) float64
- func NumericalConcavity(ord Ordinater, x float64) float64
- func NumericalGradient(ord Ordinater, x float64) float64
- func NumericalNorm(par Tangenter, t float64) maf.Vec
- func NumericalNormal(par Positioner, t float64) maf.Vec
- func NumericalNormalRadius(par Positioner, t float64) (maf.Vec, float64)
- func NumericalOrdGradConc(ord Ordinater, x float64) (float64, float64, float64)
- func NumericalPosInwardsTanFunc(pos func(t float64) maf.Vec, cen float64) func(t float64) (maf.Vec, maf.Vec)
- func NumericalPosTan(pos func(t float64) maf.Vec, t float64) (maf.Vec, maf.Vec)
- func NumericalPosTanFunc(pos func(t float64) maf.Vec) func(t float64) (maf.Vec, maf.Vec)
- func NumericalPosTanNormRad(par Positioner, t float64) (maf.Vec, maf.Vec, maf.Vec, float64)
- func NumericalRadius(par Positioner, t float64) float64
- func NumericalTangent(par Positioner, t float64) maf.Vec
- func Radius(v, a maf.Vec) float64
- func UnitNormal(v, a maf.Vec) maf.Vec
- func XYCartesianNumericalPosTanNormRad(ord Ordinater, x float64) (maf.Vec2, maf.Vec2, maf.Vec2, float64)
- func XYCartesianNumericalRadius(ord Ordinater, x float64) float64
- type Archimedean
- type Ellipse
- type ExpDecay
- type Gradienter
- type HalfLife
- type Helix
- type Ordinater
- type ParSpec
- type Parametric
- func NewArchimedean(spec Archimedean) Parametric
- func NewCircle(r float64) Parametric
- func NewCycloid(r float64) Parametric
- func NewEllipse(spec Ellipse) Parametric
- func NewHelix(spec Helix) Parametric
- func NewParametric(pos func(t float64) maf.Vec, spec ParSpec) Parametric
- func NewTimeDepArchimedean(spec kinem.Archimedean) Parametric
- func NewTimeDepHelix(spec kinem.Helical) Parametric
- func NewTimeDepProjectile(spec kinem.Projectile) Parametric
- func (par Parametric) CentreOfCurvature(t float64) maf.Vec
- func (par Parametric) NormRad(t float64) (maf.Vec, float64)
- func (par Parametric) Normal(t float64) maf.Vec
- func (par Parametric) Osculating(t float64) maf.Circle
- func (par Parametric) PosTan(t float64) (maf.Vec, maf.Vec)
- func (par Parametric) PosTanFunc() func(t float64) (maf.Vec, maf.Vec)
- func (par Parametric) PosTanNormRad(t float64) (maf.Vec, maf.Vec, maf.Vec, float64)
- func (par Parametric) Position(t float64) maf.Vec
- func (par Parametric) Radius(t float64) float64
- func (par Parametric) Tangent(t float64) maf.Vec
- type Positioner
- type Sinusoid
- type Standing
- type Tangenter
- type XYCarSpec
- type XYCartesian
- func (car XYCartesian) Concavity(x float64) float64
- func (car XYCartesian) Gradient(x float64) float64
- func (car XYCartesian) Normal(x float64) maf.Vec2
- func (car XYCartesian) OrdGradConc(x float64) (float64, float64, float64)
- func (car XYCartesian) Ordinate(x float64) float64
- func (car XYCartesian) Position(x float64) maf.Vec2
- func (car XYCartesian) Radius(x float64) float64
- func (car XYCartesian) Tangent(x float64) maf.Vec2
Constants ¶
const ( // H is the small variable increment for numerical approximations. // // The value of H is a balance between increment size (smaller is better) // and significant digits (more is better). // // Determined through trial and error on the sin function. H = 1e-6 )
Variables ¶
var Sin = NewParametric( func(t float64) maf.Vec { return maf.Vec{X: t, Y: math.Sin(t)} }, ParSpec{ Tangent: func(t float64) maf.Vec { return maf.Vec{X: 1, Y: math.Cos(t)}.Unit() }, Normal: func(t float64) maf.Vec { s, c := math.Sincos(t) kn := maf.Vec{X: c, Y: -1}.Scale(s / ((1 + c*c) * (1 + c*c))) return kn.Unit() }, Radius: func(t float64) float64 { s, c := math.Sincos(t) kn := maf.Vec{X: c, Y: -1}.Scale(s / ((1 + c*c) * (1 + c*c))) return 1.0 / kn.Mag() }, PosTan: func(t float64) (maf.Vec, maf.Vec) { s, c := math.Sincos(t) return maf.Vec{X: t, Y: s}, maf.Vec{X: 1, Y: c}.Unit() }, NormRad: func(t float64) (maf.Vec, float64) { s, c := math.Sincos(t) kn := maf.Vec{X: c, Y: -1}.Scale(s / ((1 + c*c) * (1 + c*c))) return kn.Unit(), 1.0 / kn.Mag() }, PosTanNormRad: func(t float64) (maf.Vec, maf.Vec, maf.Vec, float64) { s, c := math.Sincos(t) kn := maf.Vec{X: c, Y: -1}.Scale(s / ((1 + c*c) * (1 + c*c))) return maf.Vec{X: t, Y: s}, maf.Vec{X: 1, Y: c}.Unit(), kn.Unit(), 1.0 / kn.Mag() }, }, )
Sin is a parametric sin curve.
The curve parameter is measured in units of radians.
var SqrtH = math.Sqrt(H)
SqrtH is the square root of H.
Functions ¶
func NewArchimedeanPosTan ¶
NewArchimedeanPosTan function finds the position and unit tangent vector for the given spiral curve.
The curve parameter is measured in units of radians.
func NewCirclePosTan ¶
NewCirclePosTan function finds the position and unit tangent vector for the circle curve with the given radius.
The curve parameter is measured in units of radians.
func NewCycloidPosTan ¶
NewCycloidPosTan function finds the position and unit tangent vector for the cycloid curve generated by a rolling circle with the given radius.
The curve parameter is measured in units of radians.
func NewEllipsePosTan ¶
NewEllipsePosTan function finds the position and unit tangent vector for the ellipse curve with the given properties.
The curve parameter is measured in units of radians.
func NewHelixPosTan ¶
NewHelixPosTan function finds the position and unit tangent vector for the given helix curve.
The curve parameter is measured in units of radians.
func NewSinusoid ¶
func NewSinusoid(spec Sinusoid, decay ExpDecay) func(t float64) Parametric
NewSinusoid returns a function which constructs new parametric sinusoid curves.
The returned function accepts a time value and the curve parameter of the resulting parametric curve is measured in units of distance.
func NewSinusoidPosTan ¶
func NewSinusoidPosTan( spec Sinusoid, decay ExpDecay, ) func(t float64) func(x float64) (maf.Vec2, maf.Vec2)
NewSinusoidPosTan is a function that takes a given time value and produces, for that time value, a function that accepts distance values and produces the position and unit tangent vector for the sinusoid curve.
func NewStanding ¶
func NewStanding(spec Standing, decay ExpDecay) func(t float64) Parametric
NewStanding returns a function which constructs new parametric sinusoidal standing wave curves.
The returned function accepts a time value and the curve parameter of the resulting parametric curve is measured in units of distance.
func NewStandingPosTan ¶
func NewStandingPosTan( spec Standing, decay ExpDecay, ) func(t float64) func(x float64) (maf.Vec2, maf.Vec2)
NewStandingPosTan is a function that takes a given time value and produces, for that time value, a function that accepts distance values and produces the position and unit tangent vector for the standing wave curve.
func NewTimeDepArchimedeanPosTan ¶
NewTimeDepArchimedeanPosTan function finds the position and unit tangent vector for the given spiral curve.
The curve parameter is measured in units of time.
func NewTimeDepHelixPosTan ¶
NewTimeDepHelixPosTan function finds the position and unit tangent vector for the given helix curve.
The curve parameter is measured in units of time.
func NewTimeDepProjectilePosTan ¶
NewTimeDepProjectilePosTan function finds the position and unit tangent vector for the given projectile curve.
The curve parameter is measured in units of time.
func NumericalConc ¶
func NumericalConc(car Gradienter, x float64) float64
NumericalConc is a rough approximation of the given curve's concavity at the given abscissa.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalConcavity ¶
NumericalConcavity is an approximation of the given curve's concavity at the given abscissa.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalGradient ¶
NumericalGradient is an approximation of the given curve's gradient at the given abscissa.
func NumericalNorm ¶
NumericalNorm is a rough approximation of the given curve's unit principal normal vector at the given parameter value.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalNormal ¶
func NumericalNormal(par Positioner, t float64) maf.Vec
NumericalNormal is a rough approximation of the given curve's unit principal normal vector at the given parameter value.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalNormalRadius ¶
func NumericalNormalRadius(par Positioner, t float64) (maf.Vec, float64)
NumericalNormalRadius is a rough approximation of the given curve's unit principal normal vector and radius of curvature at the given parameter value.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalOrdGradConc ¶
NumericalOrdGradConc is the given curve's ordinate and an approximation of its gradient and concavity at the given abscissa.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalPosInwardsTanFunc ¶
func NumericalPosInwardsTanFunc( pos func(t float64) maf.Vec, cen float64, ) func(t float64) (maf.Vec, maf.Vec)
NumericalPosInwardsTanFunc returns a new function that returns both the position and a rough approximation of the given curve's unit tangent vector for a given parameter value.
The argument function defines the position of a curve. The argument float parameter value is the centre of the given function's valid domain interval.
The tangent is calculated only with positions whose parameter values are between the given parameter and the centre of the domain. This makes it safe to use at domain limits outside which the position is not defined.
func NumericalPosTan ¶
NumericalPosTan is the position and a rough approximation of the given curve's unit tangent vector at the given parameter value.
The given function shall define the position of a curve.
func NumericalPosTanFunc ¶
NumericalPosTanFunc returns a new function that returns both the position and a rough approximation of the given curve's unit tangent vector for a given parameter value.
The argument function defines the position of a curve.
func NumericalPosTanNormRad ¶
NumericalPosTanNormRad is a numerical approximation of the given curve's position, unit tangent, unit principal normal, and radius of curvature at the given parameter value.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalRadius ¶
func NumericalRadius(par Positioner, t float64) float64
NumericalRadius is a numerical approximation of the given curve's radius of curvature at the given parameter value.
At the parameter value the curve shall not be an inflection point. Nor shall the curve be linear.
func NumericalTangent ¶
func NumericalTangent(par Positioner, t float64) maf.Vec
NumericalTangent is a rough approximation of the given curve's unit tangent vector at the given parameter value.
func Radius ¶
Radius of curvature at a non-inflecting point of a curve with the given non-parallel velocity and acceleration.
func UnitNormal ¶
UnitNormal vector at a non-inflecting point of a curve with the given non-parallel velocity and acceleration.
func XYCartesianNumericalPosTanNormRad ¶
func XYCartesianNumericalPosTanNormRad(ord Ordinater, x float64) ( maf.Vec2, maf.Vec2, maf.Vec2, float64)
XYCartesianNumericalPosTanNormRad is the given curve's position and a rough numerical approximation of its unit tangent, unit principal normal, and radius of curvature at the given abscissa.
At the abscissa the curve shall not be an inflection point. Nor shall the curve be linear.
func XYCartesianNumericalRadius ¶
XYCartesianNumericalRadius is
Types ¶
type Archimedean ¶
type Archimedean struct { // Initial displacement from the origin along the X-axis. A float64 // The ratio of the radial speed to the angular speed. The distance between // the loops is 2πB assuming the polar angle is measured in radians. B float64 }
Archimedean specifies the variables of a polar coordinates equation describing an Archimedean spiral.
r = a + bθ
To infer b from an equivalent spiral trace described with physical velocities v and w:
b = v / w
type Ellipse ¶
type Ellipse struct { // A is the semi-major axis length. A float64 // B is the semi-minor axis length. B float64 }
Ellipse specifies the properties of an ellipse.
type ExpDecay ¶
type ExpDecay struct { // An exponential decay constant for a space dimension. Space float64 // An exponential decay constant in time. Time float64 }
ExpDecay contains positive decay constants for an exponential decay.
type Gradienter ¶
A Gradienter is a Cartesian curve with a known gradient at a given abscissa.
type Helix ¶
type Helix struct { // The pitch of the helix, that is, the distance travelled along the Z-axis // in one complete helix turn. P float64 // The radius of the enclosing cylinder of the helix. R float64 }
Helix specifies the properties of a helix.
type ParSpec ¶
type ParSpec struct { // Optional. Defines the unit tangent direction vector of the curve. Tangent func(t float64) maf.Vec // Optional. Defines the unit principal normal vector of the curve. Normal func(t float64) maf.Vec // Optional. Defines the radius of curvature of the curve. Radius func(t float64) float64 // Optional. Defines the position of the curve and the unit tangent // direction vector of the curve. May be more efficient than calling // position and tangent separately. PosTan func(t float64) (maf.Vec, maf.Vec) // Optional. Defines the unit principal normal vector and the radius of // curvature of the curve. May be more efficient than calling normal and // radius separately. NormRad func(t float64) (maf.Vec, float64) // Optional. Defines the position, unit tangent direction vector, unit // principal normal vector and radius of curvature of the curve. May be more // efficient than calling position, tangent, normal, and radius separately. PosTanNormRad func(t float64) (maf.Vec, maf.Vec, maf.Vec, float64) }
ParSpec specifies some extra function(s) that define a parametric curve.
Optional functions should be specified if possible and they take precedence over their equivalent approximate numerical methods which are substituted in their absence.
Note that combination functions and dedicated functions can use different ways of calculating the same property and hence may return somewhat different values.
type Parametric ¶
type Parametric struct {
// contains filtered or unexported fields
}
A Parametric curve in 3D space.
Note that the combination methods which compute multiple curve properties at once may use different methods than the dedicated methods and hence may return somewhat different values.
func NewArchimedean ¶
func NewArchimedean(spec Archimedean) Parametric
NewArchimedean constructs a new parametric Archimedean spiral curve.
The curve parameter is measured in units of radians.
The curve is constrained to the XY-plane and starts at the origin or on the X-axis.
func NewCircle ¶
func NewCircle(r float64) Parametric
NewCircle constructs a new parametric circle curve with the given radius.
The curve parameter is measured in units of radians.
func NewCycloid ¶
func NewCycloid(r float64) Parametric
NewCycloid constructs a new parametric cycloid curve generated by a rolling circle with the given radius.
The curve parameter is measured in units of radians.
The parametric equation of the curve with radius a is
X = a (t − sin(t)) Y = a (1 − cos(t)) Z = 0
where 0 <= t <= 2π.
func NewEllipse ¶
func NewEllipse(spec Ellipse) Parametric
NewEllipse constructs a new parametric ellipse curve with the given properties.
The curve parameter is measured in units of radians.
func NewHelix ¶
func NewHelix(spec Helix) Parametric
NewHelix constructs a new parametric helix curve.
The curve parameter is measured in units of radians.
The helix rotates around the Z-axis and starts on the positive X-axis.
func NewParametric ¶
func NewParametric(pos func(t float64) maf.Vec, spec ParSpec) Parametric
NewParametric constructs a new Parametric.
The first, and always necessary, argument is the position function which defines the curve.
func NewTimeDepArchimedean ¶
func NewTimeDepArchimedean(spec kinem.Archimedean) Parametric
NewTimeDepArchimedean constructs a new parametric Archimedean spiral curve.
The curve parameter is measured in units of time.
The curve is constrained to the XY-plane and starts at the origin or on the X-axis.
func NewTimeDepHelix ¶
func NewTimeDepHelix(spec kinem.Helical) Parametric
NewTimeDepHelix constructs a new parametric helix curve.
The curve parameter is measured in units of time.
The helix rotates around the Z-axis and starts on the positive X-axis.
func NewTimeDepProjectile ¶
func NewTimeDepProjectile(spec kinem.Projectile) Parametric
NewTimeDepProjectile constructs a new parametric projectile curve.
The curve parameter is measured in units of time.
The motion is constrained to the XY-plane, starts at the origin, and is subject to a constant acceleration parallel to the Y-axis.
Beware of the degenerate case of a projectile with no horizontal velocity component. Such a straight-line-ish motion is not a very good subject for a parametric curve.
func (Parametric) CentreOfCurvature ¶
func (par Parametric) CentreOfCurvature(t float64) maf.Vec
CentreOfCurvature of the curve, if it exists, at the given curve parameter.
func (Parametric) NormRad ¶
func (par Parametric) NormRad(t float64) (maf.Vec, float64)
NormRad is the unit principal normal vector and radius of curvature of the curve at the given curve parameter.
May be more efficient than calling normal and radius separately.
func (Parametric) Normal ¶
func (par Parametric) Normal(t float64) maf.Vec
Normal is the unit principal normal vector of the curve at the given curve parameter.
func (Parametric) Osculating ¶
func (par Parametric) Osculating(t float64) maf.Circle
Osculating circle of the curve, if it exists, at the given curve parameter.
func (Parametric) PosTan ¶
PosTan is the position and unit tangent direction vector of the curve at the given curve parameter.
May be more efficient than calling position and tangent separately.
func (Parametric) PosTanFunc ¶
PosTanFunc is the function used by PosTan.
func (Parametric) PosTanNormRad ¶
PosTanNormRad is the position, unit tangent direction vector, unit principal normal vector, and radius of curvature of the curve at the given curve parameter.
May be more efficient than calling position, tangent, normal, and radius separately.
func (Parametric) Position ¶
func (par Parametric) Position(t float64) maf.Vec
Position of the curve at the given curve parameter.
func (Parametric) Radius ¶
func (par Parametric) Radius(t float64) float64
Radius of curvature of the curve at the given curve parameter.
type Positioner ¶
A Positioner is a parametric curve with a known position at a given curve parameter value.
type Sinusoid ¶
type Sinusoid struct { // Amplitude. Maximum displacement from Y = 0. A float64 // Wavelength. L float64 // Phase. The angle of the oscillation at t = 0, measured in radians. P float64 // Linear speed. V float64 }
Sinusoid specifies the properties of a sine wave travelling to the right.
type Standing ¶
type Standing struct { // Amplitude. Maximum displacement from Y = 0. // // This is twice the maximum amplitude of the two constituent waves that // form this resulting standing wave. A float64 // Wavelength. L float64 // Angular velocity, related to the frequency (f) by: w = 2πf. W float64 }
Standing specifies the properties of a sinusoidal standing wave.
type Tangenter ¶
A Tangenter is a parametric curve with a known unit tangent at a given curve parameter value.
type XYCarSpec ¶
type XYCarSpec struct { // Optional. Defines the gradient (first derivative) of the curve. Gradient func(x float64) float64 // Optional. Defines the concavity (second derivative) of the curve. Concavity func(x float64) float64 // Optional. Defines the ordinate, gradient, and concavity of the curve. May // be more efficient than calling ordinate, gradient, and concavity // separately. OrdGradConc func(x float64) (float64, float64, float64) // Optional. Defines the radius of curvature of the curve. Radius func(x float64) float64 // PosTanNormRad is the position, unit tangent direction vector, unit // principal normal vector, and radius of curvature of the curve at the // given curve parameter. // // May be more efficient than calling position, tangent, normal, and radius // separately. PosTanNormRad func(x float64) (maf.Vec2, maf.Vec2, maf.Vec2, float64) }
XYCarSpec specifies some extra function(s) that define a Cartesian curve in the XY-plane.
Optional functions should be specified if possible and they take precedence over approximate numerical methods which are used as a last resort.
Note that the combination function may use different methods than the dedicated functions and hence may return somewhat different values.
type XYCartesian ¶
type XYCartesian struct {
// contains filtered or unexported fields
}
An XYCartesian is a Cartesian curve in the XY plane.
Note that the combination methods which compute multiple curve properties at once may use different methods than the dedicated methods and hence may return somewhat different values.
func NewXYCartesian ¶
func NewXYCartesian(ord func(float64) float64, spec XYCarSpec) XYCartesian
NewXYCartesian constructs a new XYCartesian.
The first, and always necessary, argument is the ordinate function which defines the curve and maps the abscissa (X-coordinate) to the corresponding ordinate (Y-coordinate).
func (XYCartesian) Concavity ¶
func (car XYCartesian) Concavity(x float64) float64
Concavity is the value of the second derivative of the curve at the given abscissa.
func (XYCartesian) Gradient ¶
func (car XYCartesian) Gradient(x float64) float64
Gradient is the value of the first derivative of the curve at the given abscissa.
func (XYCartesian) Normal ¶
func (car XYCartesian) Normal(x float64) maf.Vec2
Normal is the unit principal normal vector of the curve at the given abscissa.
func (XYCartesian) OrdGradConc ¶
func (car XYCartesian) OrdGradConc(x float64) (float64, float64, float64)
OrdGradConc is the Y-coordinate, gradient, and concavity of the curve at the given abscissa.
func (XYCartesian) Ordinate ¶
func (car XYCartesian) Ordinate(x float64) float64
Ordinate is the Y-coordinate of the curve at the given abscissa.
func (XYCartesian) Position ¶
func (car XYCartesian) Position(x float64) maf.Vec2
Position of the curve at the given abscissa.
func (XYCartesian) Radius ¶
func (car XYCartesian) Radius(x float64) float64
Radius of curvature of the curve at the given abscissa.