Class MathExpression
Simple math expression parser and evaluator
Namespace: ABB.Robotics.Math
Assembly: ABB.Robotics.Math.dll
Syntax
public class MathExpression
Remarks
Literal values should be using '.' as a decimal separator.
Constructors
View SourceMathExpression(double)
Creates a simple MathExpression from the given value
Declaration
public MathExpression(double val)
Parameters
| Type | Name | Description |
|---|---|---|
| double | val | Value to build expression for |
Remarks
Calling Evaluate() will return the given value
MathExpression(double, int)
Creates a simple MathExpression from the given value with the specified number of decimals
Declaration
public MathExpression(double val, int numDecimals)
Parameters
| Type | Name | Description |
|---|---|---|
| double | val | Value to build expression for |
| int | numDecimals | Maximum number of decimals to use |
Remarks
Calling Evaluate() will return the given value (rounded to the given number of decimals).
MathExpression(string)
Creates a new MathExpression class from a mathematical expression
Declaration
public MathExpression(string expression)
Parameters
| Type | Name | Description |
|---|---|---|
| string | expression |
MathExpression(string, bool)
Creates a new MathExpression class from a mathematical expression, optionally converting arguments of trigonometric functions from degrees
Declaration
public MathExpression(string expression, bool convertDegrees)
Parameters
| Type | Name | Description |
|---|---|---|
| string | expression | The mathematical expression |
| bool | convertDegrees | If true convert the arguments of trigonometric functions from degrees to radians |
Properties
View SourceErrorText
If the expression is invalid (IsValid returns false), this property may return more information why.
Declaration
public string ErrorText { get; }
Property Value
| Type | Description |
|---|---|
| string |
ExpressionString
Gets or sets the source expression string
Declaration
public string ExpressionString { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
IsSimple
Returns True if the expression consists of a single value
Declaration
public bool IsSimple { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsValid
Returns True if the expression is valid and can be evaluated
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
VariableNames
Returns the names of variables used in the expression
Declaration
public IEnumerable<string> VariableNames { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<string> |
Methods
View SourceEvaluate()
Evaluates the expression
Declaration
public double Evaluate()
Returns
| Type | Description |
|---|---|
| double | The evaluated value of the expression |
Evaluate(IDictionary<string, double>)
Evaluates the expression, using the passed in dictionary of variable values
Declaration
public double? Evaluate(IDictionary<string, double> variableValues)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, double> | variableValues |
Returns
| Type | Description |
|---|---|
| double? | The evaluated value of the expression |
Remarks
This overload is thread-safe, as long as no other methods on this class are called concurrently.
GetAllowedOperators()
Returns the allowed operators
Declaration
public static string[] GetAllowedOperators()
Returns
| Type | Description |
|---|---|
| string[] |
GetLinearCoefficients(string[])
Returns the linear coefficients, if this expression is linear in the set of given variables. Otherwise it returns null.
Declaration
public double[] GetLinearCoefficients(string[] variables)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | variables |
Returns
| Type | Description |
|---|---|
| double[] |
SetVariableValue(string, double)
Sets the value of a variable, which will be used the next time the expression is evaluated.
Declaration
public void SetVariableValue(string variable, double val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | variable | Name of the variable to set |
| double | val | New value of the variable |
TrySetVariableValue(string, double)
Sets the value of a variable, which will be used the next time the expression is evaluated.
Declaration
public bool TrySetVariableValue(string variable, double val)
Parameters
| Type | Name | Description |
|---|---|---|
| string | variable | Name of the variable to set |
| double | val | New value of the variable |
Returns
| Type | Description |
|---|---|
| bool | True if the variable could be set (i.e. if it exists), false otherwise |