Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CrossProduct.cs
5
7{
12 {
22 : base(Left, Right, Start, Length, Expression)
23 {
24 }
25
34 {
35 if (Left.Dimension != 3 || Right.Dimension != 3)
36 throw new ScriptRuntimeException("Cross product works on vectors of dimesion 3.", this);
37
38 if (Left is DoubleVector dv1 && Right is DoubleVector dv2)
39 {
40 double[] d1 = dv1.Values;
41 double[] d2 = dv2.Values;
42
43 return new DoubleVector(new double[] { d1[1] * d2[2] - d1[2] * d2[1], d1[2] * d2[0] - d1[0] * d2[2], d1[0] * d2[1] - d1[1] * d2[0] });
44 }
45
46 IElement[] v1 = new IElement[3];
47 Left.VectorElements.CopyTo(v1, 0);
48
49 IElement[] v2 = new IElement[3];
50 Right.VectorElements.CopyTo(v2, 0);
51
53 {
54 Arithmetics.Subtract.EvaluateSubtraction(
55 Arithmetics.Multiply.EvaluateMultiplication(v1[1], v2[2], this),
56 Arithmetics.Multiply.EvaluateMultiplication(v1[2], v2[1], this), this),
57 Arithmetics.Subtract.EvaluateSubtraction(
58 Arithmetics.Multiply.EvaluateMultiplication(v1[2], v2[0], this),
59 Arithmetics.Multiply.EvaluateMultiplication(v1[0], v2[2], this), this),
60 Arithmetics.Subtract.EvaluateSubtraction(
61 Arithmetics.Multiply.EvaluateMultiplication(v1[0], v2[1], this),
62 Arithmetics.Multiply.EvaluateMultiplication(v1[1], v2[0], this), this)
63 }, false, this);
64 }
65
66 }
67}
Class managing a script expression.
Definition: Expression.cs:39
Base class for binary vector operators.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
override IElement EvaluateVector(IVector Left, IVector Right, Variables Variables)
Evaluates the operator on vector operands.
Definition: CrossProduct.cs:33
CrossProduct(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Cross-product operator.
Definition: CrossProduct.cs:21
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for vectors.
Definition: IVector.cs:9
ICollection< IElement > VectorElements
An enumeration of vector elements.
Definition: IVector.cs:22
int Dimension
Dimension of vector.
Definition: IVector.cs:14