Math operations - HiStructClient/femcad-doc GitHub Wiki

  1. Rounding
  2. Integer extraction
  3. Odd or even number
  4. Goniometric functions
  5. Angle of vectors
  6. Equal/Not equal
  7. Convert integer to double
  8. Remainder of division

NOTE: complete list of supported math system is presented here.


Rounding of value

Following function rounds single value to specified number of decimal digits

Round( value : double, digits : integer)

example

a := 123.456789
b := Round( a, 2 )

gives

b := 123.46

If array is to be rounded, it must be done per selection

a := [ 1.23456, 0.0001, 55.555 ]
b := a.Select( i => Round( i, 1 ) )

gives

b := [1.2, 0, 55.6]

Note from msdn documentation

Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the Round(Double, Int32) method may not appear to round midpoint values to the nearest even value in the digits decimal position. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies value by 10digits, and the multiplication operation in this case suffers from a loss of precision. In case of digits == 0 or 1, if the fractional component of value is halfway between two integers, one of which is even and the other odd, the even number is returned.

Round( 0.5, 0 ) -> 0
Round( 1.5, 0 ) -> 2
Round( 2.5, 0 ) -> 2
Round( 3.5, 0 ) -> 4

Round( 3.15, 1 ) -> 3.2
Round( 3.25, 1 ) -> 3.2

Round( 2.135, 2 ) -> 2.13
Round( 3.135, 2 ) -> 3.14

Rounding down/up

Following tips helps to round down/up, althoug there is not a dedicated function for this

 rounding down => Round (a - 0.4999999999)
 rounding up => Round (a + 0.4999999999)

such functions can be also references

 res.f.RoundDown
 res.f.RoundUp

Integer extraction

Following function returns integer of a number

 Math.ToInteger(number)

example

a := 123.456
b := Math.ToInteger(a)

gives

b := 123

If you need an iteger from each item of an array, it must be done per selection

a := [1.23456,0.0001, 55.555]
b := a.Select( i => Math.ToInteger(i))

gives

b := [1, 0, 55]

Odd/Even determination

Following function determines whether particular integer is odd or even

 isOdd := i => (i-2*Math.ToInteger(i/2))!=0

Goniometric functions

The well known goniometric (trigonometric) functions has the following keywords:

 Sin (_double_), Cos(_double_), Tan(_double_)
 Asin (_double_), Acos(_double_), Atan(_double_), Atan2(_double, double_)
NOTE: It is strongly recommended to use only Atan2 as this solves whole 360° consistently,
without "omitting" the sign. Atan2 returns the angle whose tangent is the quotient of two specified numbers.

Angle between two vectors

Basic function for getting angle of vectors is included in FcsFunctions.fcs:

AngleOfVectors := u,v => Acos((u.X*v.X+u.Y*v.Y+u.Z*v.Z)/(VectorLength(u)*VectorLength(v)))

which presumes usage of of VectorLength function and DistanceTwoVertexes function. Apart from that there is also another possibility to calculate vector of two angles, moreover oriented:

Fcs.Geometry.Measure.PositiveOrientedAngleOfVectors(uB, uA, planeNormal)

example

uA := Fcs.Geometry.Vector3D(1,0,0)

uB := Fcs.Geometry.Vector3D(1,0,1)

planeNormal := Fcs.Geometry.Vector3D(0,1,0)

result := Fcs.Geometry.Measure.PositiveOrientedAngleOfVectors(uB, uA, planeNormal)

gives

 0.785398163397448    (that is 45°)

while the result for switched vectors uA <---> uB

result := Fcs.Geometry.Measure.PositiveOrientedAngleOfVectors(uA, uB, planeNormal)

is

 5.49778714378214     (that is 135°)

Equal

Below pair of symbols means "is equal to"

 ==

and this pair of symbols means "is not equal to"

 !=

Convert integer into double

Integer and double are both data types (arithmetic type specifiers) used for the definition of a variable before it is used. Integer is used as a data type to denote an integer number, whereas double is a data type to denote a big floating number.

Sometimes, FemCad cannot handle integers and request doubles. There is a small trick how to make double from an integer

 double = integer * 1.0

Result of multiplying anythin by double (1.0) is always double.

Remainder of division

We can get remainder of division by calling function

 remainder := IEEERemainder(N/D),

where N is numerator and D denominator (dividend)

⚠️ **GitHub.com Fallback** ⚠️