How to resolve the algorithm Vector products step by step in the Lua programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Vector products step by step in the Lua programming language
Table of Contents
Problem Statement
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers: (X, Y, Z). If you imagine a graph with the x and y axis being at right angles to each other and having a third, z axis coming out of the page, then a triplet of numbers, (X, Y, Z) would represent a point in the region, and a vector from the origin to the point. Given the vectors: then the following common vector products are defined:
Given the three vectors:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Vector products step by step in the Lua programming language
Source code in the lua programming language
Vector = {}
function Vector.new( _x, _y, _z )
return { x=_x, y=_y, z=_z }
end
function Vector.dot( A, B )
return A.x*B.x + A.y*B.y + A.z*B.z
end
function Vector.cross( A, B )
return { x = A.y*B.z - A.z*B.y,
y = A.z*B.x - A.x*B.z,
z = A.x*B.y - A.y*B.x }
end
function Vector.scalar_triple( A, B, C )
return Vector.dot( A, Vector.cross( B, C ) )
end
function Vector.vector_triple( A, B, C )
return Vector.cross( A, Vector.cross( B, C ) )
end
A = Vector.new( 3, 4, 5 )
B = Vector.new( 4, 3, 5 )
C = Vector.new( -5, -12, -13 )
print( Vector.dot( A, B ) )
r = Vector.cross(A, B )
print( r.x, r.y, r.z )
print( Vector.scalar_triple( A, B, C ) )
r = Vector.vector_triple( A, B, C )
print( r.x, r.y, r.z )
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Haskell programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the E programming language
You may also check:How to resolve the algorithm Bitmap step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Polymorphic copy step by step in the Elena programming language
You may also check:How to resolve the algorithm Left factorials step by step in the Factor programming language