UserManual:Tools:Formulas: Difference between revisions

From Seamly
Content added Content deleted
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 12: Line 12:
Below you'll find some examples and tips how you can use the formulas to create your pattern
Below you'll find some examples and tips how you can use the formulas to create your pattern


[[File:Advice.svg|left|frameless|50x50px]]Important Note:
=== List of buitlt-in functions ===

The formula editor is case sensitiv. So you need to spell the functions right. E.g. <code>'''acosd (wrong)'''</code> is not equal <code>'''acosD (right)'''</code>

=== Basic calculations ===
You can use <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code> to build some basic calculations. Pay attention to the dot before dash rules in math. Use brackets to influence the calculation logic.

* E.g.: 2 + 2 = 4
* E.g.: 2 - 1 = 1
* E.g.: 3 * 2 = 6
* E.g.: 3 / 2 = 1.5
* E.g.: (2 + 2) * 2 = 8
* E.g.: 2 + 2 * 2 = 6

=== List of built-in functions ===

* '''_pi''' '''⇒''' Constant value of oi, Usage: <code>'''_pi'''</code>
** E.g.: _pi = 3.14159


* '''abs''' '''⇒''' Absolute value, Usage: <code>'''abs(x)'''</code>
* '''abs''' '''⇒''' Absolute value, Usage: <code>'''abs(x)'''</code>
Line 37: Line 54:
** E.g.: asinh(90) = 5.19299
** E.g.: asinh(90) = 5.19299
* '''atan''' '''⇒''' Inverse tangent function working with radians, Usage: '''<code>atan(x)</code>'''
* '''atan''' '''⇒''' Inverse tangent function working with radians, Usage: '''<code>atan(x)</code>'''
** The arctangent is the angle whose tangent is the number. The output is an angle in radians in the range -pi/2 to pi/2
** E.g.: atan(1) = 0.78538
* '''atanD''' '''⇒''' Inverse tangent function working with degrees, Usage: '''<code>atanD(x)</code>'''
* '''atanD''' '''⇒''' Inverse tangent function working with degrees, Usage: '''<code>atanD(x)</code>'''
** The arctangent is the angle whose tangent is the number. The output is an angle in degrees in the interval [-90, 90]
** E.g.: atanD(1) = 45
* '''atanh''' '''⇒''' Inverse Hyperbolic tangent function, Usage: <code>'''atanh(x)'''</code>
* '''atanh''' '''⇒''' Inverse Hyperbolic tangent function, Usage: <code>'''atanh(x)'''</code>
** Returns the inverse hyperbolic tangent of the elements of <code>X</code>. All angles are in radians.
** E.g.: atanh(0,99) = 2.64665
* '''avg''' '''⇒''' Mean value of all arguments, Usage: '''<code>avg(arg 1; arg 2; ... arg n)</code>'''
* '''avg''' '''⇒''' Mean value of all arguments, Usage: '''<code>avg(arg 1; arg 2; ... arg n)</code>'''
** Computes the average for all values
** E.g.: avg(2;3;4) = 3
* '''cos''' '''⇒''' Cosine function working with radians, Usage: '''<code>cos(angle 0 in radians)</code>'''
* '''cos''' '''⇒''' Cosine function working with radians, Usage: '''<code>cos(angle 0 in radians)</code>'''
** Function The cosine of an angle, α, defined with reference to a right triangle is cos (α) = adjacent side hypotenuse = b h.
** E.g.: cos(1) = 0.540302
* '''cosD''' '''⇒''' Cosine function working with degrees, Usage: '''<code>cosD(angle 0 in degrees)</code>'''
* '''cosD''' '''⇒''' Cosine function working with degrees, Usage: '''<code>cosD(angle 0 in degrees)</code>'''
** Returns the icosine of the elements of <code>X</code>. All angles are in degrees.
** E.g.: cosD(180) = -1
* '''cosh''' '''⇒''' Hyperbolic cosine function, Usage: '''<code>cosh(angle 0 in radians)</code>'''
* '''cosh''' '''⇒''' Hyperbolic cosine function, Usage: '''<code>cosh(angle 0 in radians)</code>'''
** Returns the hyperbolic cosine of the elements of <code>X</code>. All angles are in radians.
** E.g.: cosh(0) = 1
* '''degTorad''' '''⇒''' Converts degrees to radians, Usage: '''<code>degTorad(angle 0 in degrees)</code>'''
* '''degTorad''' '''⇒''' Converts degrees to radians, Usage: '''<code>degTorad(angle 0 in degrees)</code>'''
** degTorad converts it's argument deg (an angle in degrees) to radians. (pi radians is 180 degrees)
** E.g.: degTorad(180) = 3.14159
* '''exp''' '''⇒''' E raised to the power of x, Usage: '''<code>exp(x) where e = 2.718</code>'''
* '''exp''' '''⇒''' E raised to the power of x, Usage: '''<code>exp(x) where e = 2.718</code>'''
** The exponential function is a mathematical function denoted by f(x)<math>f(x) = exp(x)</math> or <math>f(x) = e^x</math>
** E.g.: exp(0) = 1
** E.g.: exp(2) = 7.38906
* '''fmod''' '''⇒''' Returns the floating-point remainder of x/y (rounded towards zero), Usage: '''<code>fmod(x; y)</code>'''
* '''fmod''' '''⇒''' Returns the floating-point remainder of x/y (rounded towards zero), Usage: '''<code>fmod(x; y)</code>'''
** Returns the remainder of x divided by y.
** E.g.: fmod(3.3;2) = 1.3
* '''ln''' '''⇒''' Logarithm to base e (2.71828...), Usage: '''<code>ln(x)</code>'''
* '''ln''' '''⇒''' Logarithm to base e (2.71828...), Usage: '''<code>ln(x)</code>'''
** The '''natural logarithm''' is a logarithm in which the base is the mathematical constant, e. It is written as <code>'''ln(x)'''</code>
** E.g.: ln(10) = 2.30259
* '''log''' '''⇒''' Logarithm to base 10, Usage: '''<code>log(x)</code>'''
* '''log''' '''⇒''' Logarithm to base 10, Usage: '''<code>log(x)</code>'''
** The logarithm is a logarithm in which the base is 10. It is written as <code>'''log(x)'''</code>
** E.g.: log(10) = 1
* '''log10''' '''⇒''' Logarithm to base 10, Usage: <code>'''log10(x)'''</code>
* '''log10''' '''⇒''' Logarithm to base 10, Usage: <code>'''log10(x)'''</code>
** The logarithm is a logarithm in which the base is 10. It is written as <code>'''log10(x)'''</code>
** E.g.: log10(10) = 1
* '''log2''' '''⇒''' Logarithm to base 2, Usage: '''<code>log2(x)</code>'''
* '''log2''' '''⇒''' Logarithm to base 2, Usage: '''<code>log2(x)</code>'''
** The logarithm is a logarithm in which the base is 2. It is written as <code>'''log2(x)'''</code>
** E.g.: log2(10) = 3.32193
* '''max''' '''⇒''' Max of all arguments, Usage: '''<code>max(arg 1; arg 2; ... arg n)</code>'''
* '''max''' '''⇒''' Max of all arguments, Usage: '''<code>max(arg 1; arg 2; ... arg n)</code>'''
** Returns the max value for all values
** E.g.: max(2;3;4) = 4
* '''min''' '''⇒''' Min of all arguments, Usage: '''<code>min(arg 1; arg 2; ... arg n)</code>'''
* '''min''' '''⇒''' Min of all arguments, Usage: '''<code>min(arg 1; arg 2; ... arg n)</code>'''
** Returns the min value for all values
** E.g.: min(2;3;4) = 2
* '''radTodeg''' '''⇒''' Converts radians to degrees, Usage: '''<code>radTodeg(angle 0 in radians)</code>'''
* '''radTodeg''' '''⇒''' Converts radians to degrees, Usage: '''<code>radTodeg(angle 0 in radians)</code>'''
** radTodeg converts it's argument rad (an angle in radians) to degrees. (pi radians is 180 degrees)
** E.g.: radTodeg(3.14159) = 180
* '''rint''' '''⇒''' Round to nearest integer, Usage: '''<code>rint(float x)</code>'''
* '''rint''' '''⇒''' Round to nearest integer, Usage: '''<code>rint(float x)</code>'''
** The '''<code>rint()</code>''' function rounds the argument to an integral value using the current rounding direction.
** E.g.: rint(2.3) = 2
** If you want to round to one digit multiply the value first by 10 and divide the result by 10 again: rint(2.356*10)/10 = 2.4
* '''sign''' '''⇒''' Sign function -1 if x<0; 1 if x>0, Usage: '''<code>sign(x)</code>'''
* '''sign''' '''⇒''' Sign function -1 if x<0; 1 if x>0, Usage: '''<code>sign(x)</code>'''
** The sign function is a mathematical function that extracts the sign of a number. The sign function assigns a value of +1 to positive numbers, -1 to negative numbers, and 0 to zero.
** E.g.: sign(5) = 1
** E.g.: sign(-3) = -1
* '''sin''' '''⇒''' Sine function working with radians, Usage: '''<code>sin(angle 0 in radians)</code>'''
* '''sin''' '''⇒''' Sine function working with radians, Usage: '''<code>sin(angle 0 in radians)</code>'''
** The sine function  is one of the basic functions encountered in trigonometry. Let be an angle measured counterclockwise from the ''x''-axis along an arc of the unit circle.
** E.g.: sin(90) = 0.893997
* '''sinD''' '''⇒''' Sine function working with degrees, Usage: '''<code>sinD(angle 0 in degrees)</code>'''
* '''sinD''' '''⇒''' Sine function working with degrees, Usage: '''<code>sinD(angle 0 in degrees)</code>'''
** The sine function  is one of the basic functions encountered in trigonometry. Let be an angle measured counterclockwise from the ''x''-axis along an arc of the unit circle.
** E.g.: sinD(90) = 1
* '''sinh''' '''⇒''' Hyperbolic sine function, Usage: <code>'''sinh(angle 0 in radians)'''</code>
* '''sinh''' '''⇒''' Hyperbolic sine function, Usage: <code>'''sinh(angle 0 in radians)'''</code>
** Returns the hyperbolic sine of the elements of <code>X</code>. All angles are in radians.
** E.g.: sinh(1) = 1.1752
* '''sqrt''' '''⇒''' Square root of a value, Usage: '''<code>sqrt(x)</code>'''
* '''sqrt''' '''⇒''' Square root of a value, Usage: '''<code>sqrt(x)</code>'''
** The <code>'''sqrt(x)'''</code> function takes a single argument and returns its square root.
** E.g.: sqrt(4) = 2
* '''sum''' '''⇒''' Sum of all arguments, Usage: '''<code>sum(arg 1; arg 2; ... arg n)</code>'''
* '''sum''' '''⇒''' Sum of all arguments, Usage: '''<code>sum(arg 1; arg 2; ... arg n)</code>'''
** Computes the sum for all values
** E.g.: sum(2;3;4) = 9
* '''tan''' '''⇒''' Tangent function working with radians, Usage: '''<code>tan(angle 0 in radians)</code>'''
* '''tan''' '''⇒''' Tangent function working with radians, Usage: '''<code>tan(angle 0 in radians)</code>'''
** The '''tangent function''' is one of the basic trigonometric functions and is quite a commonly used function in trigonometry. The tangent function can be expressed as the ratio of the sine function and cosine function. In a right-angled triangle, the formula for the tangent function is expressed as the ratio of the perpendicular and base of the triangle. It can also be expressed as the reciprocal of the cotangent function.
** E.g.: tan(1) = 1.55741
* '''tanD''' '''⇒''' Tangent function working with degrees, Usage: '''<code>tanD(angle 0 in degrees)</code>'''
* '''tanD''' '''⇒''' Tangent function working with degrees, Usage: '''<code>tanD(angle 0 in degrees)</code>'''
** E.g.: tanD(45) = 1
* '''tanh''' '''⇒''' Hyperbolic tangent function, Usage: '''<code>tanh(angle 0 in radians)</code>'''</div>
* '''tanh''' '''⇒''' Hyperbolic tangent function, Usage: '''<code>tanh(angle 0 in radians)</code>'''
** Tanh is a '''hyperbolic function'''. It is the ratio of sinh and cosh.
** E.g.: tanh(45) = 1

=== Conditional statements ===
Conditional statements are useful in a multisize pattern. Depending on the measurements you can work with different values.

There is an ‘if then else’ construct. Is expressed by: ( a > b ? y : z) <code>'''(condition ? true_value : false_value)'''</code>

* E.g.: (1 > 2 ? 0.5 : 3.5) = 3.5 '''⇒''' if 1 greater than 2 then 0.5 else 3.5

* E.g.: (1 == 1 ? 0.5 : 3.5) = 0.5 '''⇒''' if 1 equal to 1 then 0.5 else 3.5
* E.g.: (1 <= 2 ? 0.5 : 3.5) = 0.5 '''⇒''' if 1 less than or equal to 2 then 0.5 else 3.5

Nested query:

* E.g.: (1 >= 2 ? 0.5 : (3 > 5 ? 2 : 3)) = 2 '''⇒''' if 1 greater than or equal to 2 then 0.5 else if 3 greater than 5 then 2 else 3

=== Working with measurments and variables ===
A main feature of Seamly2D is that you can use measurements and variables in your formulas.

* E.g.: across_chest_f/2 '''⇒''' measurement <code>across_chest_f</code> divided by 2
* E.g.: #variable/2 '''⇒''' custom variable <code>#variable</code> divided by 2
* E.g.: Line_A1_A2 + Line_A3_A4 '''⇒''' add line <code>Line_A1_A2</code> to line <code>Line_A3_A4</code></div>
</translate>
</translate>

Latest revision as of 21:36, 24 June 2024

Draft Mode - Formulas

Formulas[edit | edit source]

Below you'll find some examples and tips how you can use the formulas to create your pattern

Important Note:

The formula editor is case sensitiv. So you need to spell the functions right. E.g. acosd (wrong) is not equal acosD (right)

Basic calculations[edit | edit source]

You can use +, -, *, / to build some basic calculations. Pay attention to the dot before dash rules in math. Use brackets to influence the calculation logic.

  • E.g.: 2 + 2 = 4
  • E.g.: 2 - 1 = 1
  • E.g.: 3 * 2 = 6
  • E.g.: 3 / 2 = 1.5
  • E.g.: (2 + 2) * 2 = 8
  • E.g.: 2 + 2 * 2 = 6

List of built-in functions[edit | edit source]

  • _pi Constant value of oi, Usage: _pi
    • E.g.: _pi = 3.14159
  • abs Absolute value, Usage: abs(x)
    • Returns the absolute value of a number. The absolute value of a number is the number without its sign.
    • E.g.: abs(-1) = 1
    • E.g.: abs(1) = 1
  • acos Inverse cosine function working with radians, Usage: acos(x)
    • The arccosine function is the inverse function of the cosine function and calculates the angle for a given cosine. X must be in the [-1..1] range. The result is an angle expressed in radians.
    • E.g.: acos(0.1) = 1.47063
  • acosD Inverse cosine function working with degrees, Usage: acosD(x)
    • For values of X in the interval [-1, 1], acosd(X) returns values in the interval [0, 180]
    • E.g.: acosD(-1) = 180
  • acosh Inverse Hyperbolic cosine function, Usage: acosh(x)
    • Returns the inverse hyperbolic cosine of a number. The number must be greater than 1.
    • E.g.: acosh(2) = 1.31696
  • asin Inverse sine function working with radians, Usage: asin(x)
    • It returns the inverse sine of a value, given a ratio of a triangle's opposite side over its hypotenuse. The asin()function is a trigonometric function that returns the inverse sine of a number between -1 and 1. The function contains a single calculation that returns the number of radians representing an <angle> between -90deg and 90deg.
    • E.g.: asin(-1) = -1.5708
  • asinD Inverse sine function working with degrees, Usage: asinD(x)
    • The function accepts both real and complex inputs. For real values of X in the interval [-1, 1], asind(X) returns values in the interval [-90, 90].
    • E.g.: asinD(1) = 90
  • asinh Inverse Hyperbolic sine function, Usage: asinh(x)
    • Returns the inverse hyperbolic sine of the elements of X. All angles are in radians.
    • E.g.: asinh(90) = 5.19299
  • atan Inverse tangent function working with radians, Usage: atan(x)
    • The arctangent is the angle whose tangent is the number. The output is an angle in radians in the range -pi/2 to pi/2
    • E.g.: atan(1) = 0.78538
  • atanD Inverse tangent function working with degrees, Usage: atanD(x)
    • The arctangent is the angle whose tangent is the number. The output is an angle in degrees in the interval [-90, 90]
    • E.g.: atanD(1) = 45
  • atanh Inverse Hyperbolic tangent function, Usage: atanh(x)
    • Returns the inverse hyperbolic tangent of the elements of X. All angles are in radians.
    • E.g.: atanh(0,99) = 2.64665
  • avg Mean value of all arguments, Usage: avg(arg 1; arg 2; ... arg n)
    • Computes the average for all values
    • E.g.: avg(2;3;4) = 3
  • cos Cosine function working with radians, Usage: cos(angle 0 in radians)
    • Function The cosine of an angle, α, defined with reference to a right triangle is cos (α) = adjacent side hypotenuse = b h.
    • E.g.: cos(1) = 0.540302
  • cosD Cosine function working with degrees, Usage: cosD(angle 0 in degrees)
    • Returns the icosine of the elements of X. All angles are in degrees.
    • E.g.: cosD(180) = -1
  • cosh Hyperbolic cosine function, Usage: cosh(angle 0 in radians)
    • Returns the hyperbolic cosine of the elements of X. All angles are in radians.
    • E.g.: cosh(0) = 1
  • degTorad Converts degrees to radians, Usage: degTorad(angle 0 in degrees)
    • degTorad converts it's argument deg (an angle in degrees) to radians. (pi radians is 180 degrees)
    • E.g.: degTorad(180) = 3.14159
  • exp E raised to the power of x, Usage: exp(x) where e = 2.718
    • The exponential function is a mathematical function denoted by f(x) or
    • E.g.: exp(0) = 1
    • E.g.: exp(2) = 7.38906
  • fmod Returns the floating-point remainder of x/y (rounded towards zero), Usage: fmod(x; y)
    • Returns the remainder of x divided by y.
    • E.g.: fmod(3.3;2) = 1.3
  • ln Logarithm to base e (2.71828...), Usage: ln(x)
    • The natural logarithm is a logarithm in which the base is the mathematical constant, e. It is written as ln(x)
    • E.g.: ln(10) = 2.30259
  • log Logarithm to base 10, Usage: log(x)
    • The logarithm is a logarithm in which the base is 10. It is written as log(x)
    • E.g.: log(10) = 1
  • log10 Logarithm to base 10, Usage: log10(x)
    • The logarithm is a logarithm in which the base is 10. It is written as log10(x)
    • E.g.: log10(10) = 1
  • log2 Logarithm to base 2, Usage: log2(x)
    • The logarithm is a logarithm in which the base is 2. It is written as log2(x)
    • E.g.: log2(10) = 3.32193
  • max Max of all arguments, Usage: max(arg 1; arg 2; ... arg n)
    • Returns the max value for all values
    • E.g.: max(2;3;4) = 4
  • min Min of all arguments, Usage: min(arg 1; arg 2; ... arg n)
    • Returns the min value for all values
    • E.g.: min(2;3;4) = 2
  • radTodeg Converts radians to degrees, Usage: radTodeg(angle 0 in radians)
    • radTodeg converts it's argument rad (an angle in radians) to degrees. (pi radians is 180 degrees)
    • E.g.: radTodeg(3.14159) = 180
  • rint Round to nearest integer, Usage: rint(float x)
    • The rint() function rounds the argument to an integral value using the current rounding direction.
    • E.g.: rint(2.3) = 2
    • If you want to round to one digit multiply the value first by 10 and divide the result by 10 again: rint(2.356*10)/10 = 2.4
  • sign Sign function -1 if x<0; 1 if x>0, Usage: sign(x)
    • The sign function is a mathematical function that extracts the sign of a number. The sign function assigns a value of +1 to positive numbers, -1 to negative numbers, and 0 to zero.
    • E.g.: sign(5) = 1
    • E.g.: sign(-3) = -1
  • sin Sine function working with radians, Usage: sin(angle 0 in radians)
    • The sine function  is one of the basic functions encountered in trigonometry. Let be an angle measured counterclockwise from the x-axis along an arc of the unit circle.
    • E.g.: sin(90) = 0.893997
  • sinD Sine function working with degrees, Usage: sinD(angle 0 in degrees)
    • The sine function  is one of the basic functions encountered in trigonometry. Let be an angle measured counterclockwise from the x-axis along an arc of the unit circle.
    • E.g.: sinD(90) = 1
  • sinh Hyperbolic sine function, Usage: sinh(angle 0 in radians)
    • Returns the hyperbolic sine of the elements of X. All angles are in radians.
    • E.g.: sinh(1) = 1.1752
  • sqrt Square root of a value, Usage: sqrt(x)
    • The sqrt(x) function takes a single argument and returns its square root.
    • E.g.: sqrt(4) = 2
  • sum Sum of all arguments, Usage: sum(arg 1; arg 2; ... arg n)
    • Computes the sum for all values
    • E.g.: sum(2;3;4) = 9
  • tan Tangent function working with radians, Usage: tan(angle 0 in radians)
    • The tangent function is one of the basic trigonometric functions and is quite a commonly used function in trigonometry. The tangent function can be expressed as the ratio of the sine function and cosine function. In a right-angled triangle, the formula for the tangent function is expressed as the ratio of the perpendicular and base of the triangle. It can also be expressed as the reciprocal of the cotangent function.
    • E.g.: tan(1) = 1.55741
  • tanD Tangent function working with degrees, Usage: tanD(angle 0 in degrees)
    • E.g.: tanD(45) = 1
  • tanh Hyperbolic tangent function, Usage: tanh(angle 0 in radians)
    • Tanh is a hyperbolic function. It is the ratio of sinh and cosh.
    • E.g.: tanh(45) = 1

Conditional statements[edit | edit source]

Conditional statements are useful in a multisize pattern. Depending on the measurements you can work with different values.

There is an ‘if then else’ construct. Is expressed by: ( a > b ? y : z) (condition ? true_value : false_value)

  • E.g.: (1 > 2 ? 0.5 : 3.5) = 3.5 if 1 greater than 2 then 0.5 else 3.5
  • E.g.: (1 == 1 ? 0.5 : 3.5) = 0.5 if 1 equal to 1 then 0.5 else 3.5
  • E.g.: (1 <= 2 ? 0.5 : 3.5) = 0.5 if 1 less than or equal to 2 then 0.5 else 3.5

Nested query:

  • E.g.: (1 >= 2 ? 0.5 : (3 > 5 ? 2 : 3)) = 2 if 1 greater than or equal to 2 then 0.5 else if 3 greater than 5 then 2 else 3

Working with measurments and variables[edit | edit source]

A main feature of Seamly2D is that you can use measurements and variables in your formulas.

  • E.g.: across_chest_f/2 measurement across_chest_f divided by 2
  • E.g.: #variable/2 custom variable #variable divided by 2
  • E.g.: Line_A1_A2 + Line_A3_A4 add line Line_A1_A2 to line Line_A3_A4