Code: Select all
''bluatigro 31 jun 2022
''test lirary v3d
gosub [v3d]
call v3d 1,2,3
call v3d.uit x,y,z
print "v3d 1 =",x,y,z
call v3d 4,5,7
call v3d.uit a,b,c
print "v3d 2 =",a,b,c
call v3d.add x,y,z , a,b,c
call v3d.uit e,f,g
print "v3d 2+1 =",e,f,g
call v3d.sub x,y,z , a,b,c
call v3d.uit e,f,g
print "v3d 1-2 =",e,f,g
call v3d.div x,y,z , 2
call v3d.uit e,f,g
print "v3d 1 / 2 =",e,f,g
call v3d.mul x,y,z , 2
call v3d.uit e,f,g
print "v3d 1 * 2 =",e,f,g
print "len v3d 1 =" ,v3d.len(x,y,z)
print "len v3d 2 =" ,v3d.len(a,b,c)
print "angle v1 v2 =" ,v3d.angle( x,y,z , a,b,c )
call v3d.cross x,y,z , a,b,c
call v3d.uit e,f,g
print "v3d 1 2 cross =",e,f,g
end
'include "@v3d.bas"
Code: Select all
''bluatigro 31 jul 2022
''v3d library
[v3d]
''declaration
global v3d.x,v3d.y,v3d.z
return
sub v3d x , y , z
''constructor
v3d.x = x
v3d.y = y
v3d.z = z
end sub
sub v3d.uit byref x , byref y , byref z
x = v3d.x
y = v3d.y
z = v3d.z
end sub
sub v3d.add x1,y1,z1 , x2,y2,z2
''operator v3d1+v3d2
call v3d x1+x2 , y1+y2 , z1+z2
end sub
sub v3d.sub x1,y1,z1 , x2,y2,z2
''operator v3d1-v3d2
call v3d x1-x2 , y1-y2 , z1-z2
end sub
sub v3d.div x1,y1,z1 , d
''operator v3d1/d
call v3d x1/d , y1/d , z1/d
end sub
sub v3d.mul x1,y1,z1 , d
''operator v3d1*d
call v3d x1*d , y1*d , z1*d
end sub
function v3d.dot( x1,y1,z1 , x2,y2,z2 )
v3d.dot = x1*x2 + y1*y2 + z1*z2
end function
function v3d.len( x1,y1,z1 )
'' |v|
v3d.len = sqr( v3d.dot( x1,y1,z1 , x1,y1,z1 ) )
end function
function v3d.angle( x1,y1,z1 , x2,y2,z2 )
l1 = v3d.len( x1,y1,z1 )
l2 = v3d.len( x2,y2,z2 )
d = v3d.dot( x1,y1,z1 , x2,y2,z2 )
v3d.angle = acs( d / ( l1 * l2 ) )
end function
sub v3d.cross x1,y1,z1 , x2,y2,z2
call v3d y1*z2 - z1*y2 _
, z1*x2 - x1*z2 _
, x1*y2 - y2*x2
end sub