Formulas
General
The functions Formula Spline, Formula Animation and Formula Deformer, among others, indicate that mathematical formulas can be entered in Cinema 4D. But this is not only possible at these prominent locations - no! - At any point in the program where you can enter values (e.g. in the Attribute Manager), such expressions can be set instead of a fixed numerical value. Let C4D do the math for you!
Below you will find a list of all possible units, operators, functions and constants.
Please use only the dot as decimal separator . - no comma. If a comma is accepted in one or other input field, this happens by chance and also depends on your operating system settings. Thousands separators are generally not permitted. Spaces can be used for a better overview, but have no influence on the formula evaluation.
Arguments such as mod(a;b) must be separated by a semicolon or by square brackets [] (then without round brackets).
rnd(100) is the same as rnd[100] and rnd(100;234) is the same as rnd([100][234]).
Symbol / Function | Meaning | Example |
---|---|---|
Calculation operators | ||
+ | Addition | 144+14 = 158 |
- | Subtraction | 144-14 = 130 |
* | Multiplication | 144*2 = 288 |
/ | Division | 144/12 = 12 |
() | Brackets | (3+4)*2 = 14 |
Units | ||
km | Kilometer | 1km = 1000m |
m | Meter | 1m = 100cm |
cm | Centimeter | 1cm = 0.01m |
mm | Millimeter | 1mm = 0.001m |
um | Micrometer | 1um = 0.000001m |
nm | Nanometer | 1nm = 0.000000001m |
mi | Mile | 1mi = 1609.344 m |
yd | Yard | 1yd = 0.914m |
ft | Foot | 1ft = 0.305m |
in | Inch | 1in = 0.025m |
F | Frame number | |
Logical operators | ||
= | Is the same | 1km = 1000m |
== | Is identical | Positive signal (true) if the values to the left and right of '==' are identical |
> | Larger than | Positive signal (true) if the value to the left of '>' is greater than the value after '>' |
< | Smaller than | Positive signal (true) if the value to the left of '<' is less than the value behind '<' |
>= | Larger equals | Positive signal (true) if the value to the left of '>=' is greater than or equal to the value after '>=' |
<= | Smaller equal | Positive signal (true) if the value to the left of '<=' is less than or equal to the value after '<=' |
!= | Not equal | Positive signal (true) if the values to the left and right of '!=' are not identical |
! | Not | Inverting a property. True becomes false and vice versa. |
|| or | Or | Positive signal if either the property before or after '||' is true |
&& or and | And | Positive signal if the properties before and after '&&' are true |
& | Bitwise And | – |
| | Bitwise Or | – |
^ | Excl. bitwise Or | – |
~ | Bitwise not | – |
?(a;b) | Ternary operator | If the preceding condition is fulfilled, 'a' is output, otherwise 'b': (3>4)?(10;20) = 20 |
Constants | ||
e | Euler's number | ≈ 2.71828 |
pi | Circular number Pi | ≈ 3.14159 |
pi05 | Half a pi | ≈ 1.57079 |
pi2 | Double Pi | ≈ 6.28318 |
piinv | Inverse Pi | 1/pi ≈ 0.31831 |
pi05inv | Inverse half pi | 1/pi05 ≈ 0.63662 |
pi2inv | Inverse double pi | 1/pi2 ≈ 0.159155 |
Functions | ||
sin(a) | Sin | – |
cos(a) | Cosine | – |
acos(a) | Arcus cosine | – |
asin(a) | Arcus sine | – |
tan(a) | Tangent | – |
atan(a) | Arcus tangent | – |
cosh(a) | Hyperbolic cosine | – |
sinh(a) | Hyperbolic sinus | – |
tanh(a) | Hyperbolic tangent | – |
floor(a) | Round off | floor(11.8) = 11 |
ceil(a) | Round up | ceil(11.2) = 12 |
round(a) | Rounds | round(11.8) = 12 round(11.2) = 11 |
abs(a) | Absolute value | abs(-11.3) = 11.3 |
sqr(a) | Square power | sqr(5) = 52 = 25 |
sqrt(a) | Square root | sqrt(25) = 5 |
exp(a) | Exponential function | exp(5) = 148.4132 |
log10(a) | Logarithm to base 10 | log10(100) = 2 |
log(a) | Logarithm to the base e | log(e) = 1 |
trunc(a) | Truncation of decimal places | trunc(-1.893) = -1 |
rnd(a{;b}) | Random value between 0 and a; opt. with b as seed value | - |
pow(a;b) | Potency | pow(2;3) = 23 = 8 |
mod(a;b) | Modulo | mod(10;4) = 10 - 2*4 = 2 mod(15;3) = 15 - 5*3 = 0 |
clamp(a;b;c) | Limit value c to the range between a and b | clamp(2;6;10) = 6 clamp(2;6;1) = 2 |
min(a;b) | Minimum of both values | min(4;7) = 4 |
max(a;b) | Maximum of both values | max(4;7) = 7 |
(a)<<(b) or (a)shl(b) |
Move bit by bit to the left | 1<<4 = 16 |
(a)>>(b) or (a)shr(b) |
Move bit by bit to the right | 1000>>4 = 16 |
len(x;y{;z}) | Length of a 2D/3D vector | len(1;1) = 1.414 len(1;1;1) = 1.7321 |
Curly brackets (e.g. 'rnd(a{;b})') symbolize optional values that do not have to be entered.
Please also note the special variables in connection with multiple selection in the next paragraph.
Extended formula input for multiple selections
Wherever numbers can be entered in the Attribute Manager, it is possible to enter formulas in common parameter fields for several simultaneously selected objects in order to change the respective value in different ways.
There are the following variables:
- x: The variable for the original value.
- num: Index value. The selected elements/objects are numbered consecutively.
- tot: The total number of selected elements/objects.
and this function:
- rnd(value): A random value between . 0 and 'Value' is determined.
Examples:
- You have 3 spheres. These are set (parameter P.X) to 100, 200 and 300 meters. If you now select all 3 spheres and enter x+200 for P.X, the spheres will be placed at 300, 400 and 500 meters.
- 10 light sources: You want to increase the intensity of the light sources in steps of 20 starting from 0. Select the light sources and enter num*20 for Intensity. According to the order in the Object Manager, the first light source has an Intensity of 0, the second 20, the third 40 and so on.
- You want to randomly distribute the intensity of 10 light sources within a value range of 200. Select all light sources and enter x+rnd(200) for Intensity. If all light sources previously had an Intensity of 0, each now has a random intensity within the value range 200.
- For 28 cubes, you want to define the parameter Fillet Radius from 0 to 100 with the same difference from cube to cube. Select all cubes and enter 100*(num/(tot-1)) for Fillet Radius.
Uniform enlargement of the cube roundings.
Units
You have the option of specifying your own unit regardless of the unit selected in the default settings.
Functions
The argument of trigonometric functions is always interpreted in degrees. For example, entering sin(2*pi) does not mean calculating the sine of 360°, but only for approx. 6.283°.
General
With the options just described, you should be able to create even the most complex actions accurately. Remember, you can use the various above-mentioned Shuffle points as desired. The following input would be quite conceivable:
2 km + exp (sin (4 mm * pi)) / ((sin (14 cm)) ^ 2 + (cos (14 cm)) ^ 2)
Such constructs are possible with logical operators, for example:
(rnd(100)<50)?(100;200)
Here, the value '100' or '200' is spit out with an approx. 50% probability in each case by forming random numbers between 0 and 100 ('rnd(100)'). A query is then made as to whether these are less than 50, if yes, '100' is output, if not '200'.