Vector fields
ns fields
(:require [fastmath.fields :as fields]
(:as codox])) [fastmath.dev.codox
Reference
fastmath.fields
Vector field functions.
Vector fields are functions R2->R2.
Names are taken from fractal flames world where such fields are call variations
. Most implementations are taken from JWildfire software.
### Creation
To create vector field call field multimethod with name of the field as keyword.
Some of the vector fields require additional configuration as a map of parameters as keywords and values. Call parametrization to create random one or to merge with provided.
Additionally you can provide amount
parameter which is scaling factor for vector field (default: 1.0
).
### Derived fields
You can use several method to derive new vector field from the other one(s). Possible options are:
- derivative, grad-x, grad-y - directional derivative of the field
- sum - sum of two fields
- multiply - multiplication of the fields
- composition - composition of the fields
- angles - angles of the field vectors
### Scalar fields
You can derive scalar fields from given vector field(s):
- jacobian - determinant of jacobian matrix
- divergence - divergence of the field
- cross - cross product of the fields (as a determinant of the 2x2 matrix of vectors)
- dot - dot product
- angle-between - angle between vectors from fields.
### Combinations
The other option is to create vector field using some of the above possibilities. Combination is a tree of field operations with parametrizations. Functions:
- combine - create vector field randomly of from given parametrization.
- random-configuration - returns random configuration as a map
- randomize-configuration - change parametrization for given configuration.
skip-random-fields
When random configuration for combine is used. Skip vector fields which are random.
angle-between
Angle between input vector and result of the vector field.
In case when two vector fields are given, cross product is taken from result of vector fields.
Resulting value is from range [-PI,PI]
.
combine
(combine {:keys [type name amount config var step var1 var2]})
(combine)
Create composite vector field function based on configuration
Call without argument to get random vector field.
Configuration is a tree structure where nodes are one of the following
{:type :variation :name NAME :amount AMOUNT :config CONFIG}
where- NAME is variation name (keyword)
- AMOUNT is scaling factor
- CONFIG is variation parametrization
{:type :operation :name OPERATION :amount AMOUNT :var1 VAR1 :var2 VAR2}
where- OPERATION is one of the operations (see below)
- AMOUNT is scaling factor
- VAR1 and VAR2 two variations to combine
{:type :operation :name :derivative :amount AMOUNT :var VAR :step STEP}
where- AMOUNT is scaling factor
- VAR variation, subject to calculate derivative
- STEP dx and dy value
Possible OPERATIONs are:
:add
- sum of two variations:mult
- multiplication:comp
- composition:angles
- vector field from angles
See random-configuration for example.
composition
(composition f1 f2 amount)
(composition f1 f2)
Compose two vector fields.
cross
2d cross product (det of the 2x2 matrix) of the input vector and result of the vector field.
In case when two vector fields are given, cross product is taken from results of vector fields.
curl
(curl f)
(curl f h)
Curl (2d version) of the field.
See: https://youtu.be/rB83DpBJQsE?t=855
derivative
(derivative f amount h)
(derivative f h)
(derivative f)
Calculate directional derivative of fn. Derivative is calculated along [1,1] vector with h
as a step (default 1.0e-6
).
divergence
(divergence f)
(divergence f h)
Divergence of the field.
See: https://youtu.be/rB83DpBJQsE?t=855
dot
Dot product of the input vector and result of the vector field.
In case when two vector fields are given, cross product is taken from result of vector fields.
field
Return vector field for given name and options: amount (scaling factor) and parametrization.
Default scaling factor is 1.0, default parametrization is random.
Resulting function operates on Vec2 type.
fields-list
fields-list-not-random
fields-list-random
fields-map
grad-x
(grad-x f amount h)
(grad-x f h)
(grad-x f)
Calculate gradient along x axis.
grad-y
(grad-y f amount h)
(grad-y f h)
(grad-y f)
Calculate gradient along y axis.
heading
(heading f)
Angle of the vectors from field.
jacobian
(jacobian f)
(jacobian f h)
Det of Jacobian of the field
magnitude
(magnitude f)
Magnitude of the vectors from field.
multiplication
(multiplication f1 f2 amount)
(multiplication f1 f2)
Multiply two vector fields (as a element-wise multiplication of results).
parametrization
Return random parametrization map for given field.
Optinally you can pass part of the parametrization. In this case function will add remaining keys with randomly generated values.
If field doesn’t have parametrization, empty map will be returned.
See field.
random-configuration
(random-configuration)
(random-configuration depth)
(random-configuration depth f)
Create random configuration for combine function. Optionally with depth (0 = only root is created).
See combine for structure.
Bind *skip-random-fields*
to true to exclude fields which are random.
random-field
(random-field)
(random-field depth)
Create randomized field (optional depth can be provided).
randomize-configuration
(randomize-configuration f)
Randomize values for given configuration. Keeps structure untouched.
scalar->vector-field
(scalar->vector-field scalar f)
(scalar->vector-field scalar f1 f2)
Returns vector field build from scalar fields of the input vector and result of the vector field.
sum
(sum f1 f2 amount)
(sum f1 f2)
Add two vector fields.
source: clay/fields.clj