Code: Select all
--this converts a vector into absolute value
function vector.abs(vector)
vector.x = math.abs(vector.x)
vector.y = math.abs(vector.y)
vector.z = math.abs(vector.z)
return(vector)
end
Code: Select all
--this converts a vector into absolute value
function vector.abs(vector)
vector.x = math.abs(vector.x)
vector.y = math.abs(vector.y)
vector.z = math.abs(vector.z)
return(vector)
end
Right here: https://github.com/minetest/minetest/bl ... vector.luaOil_boi wrote:I can't find where the vector library is stored in the game engine
I think, you confused that with the function vector.length. What OP says is not any kind of norm. It only makes all coordinates positive.sfan5 wrote:Right here: https://github.com/minetest/minetest/bl ... vector.luaOil_boi wrote:I can't find where the vector library is stored in the game engine
This can be used for collision detectionHume2 wrote:I think, you confused that with the function vector.length. What OP says is not any kind of norm. It only makes all coordinates positive.sfan5 wrote:Right here: https://github.com/minetest/minetest/bl ... vector.luaOil_boi wrote:I can't find where the vector library is stored in the game engine
Code: Select all
pos = vector.new(0,0,0)
pos2 = vector.new(0.5,0,0)
Code: Select all
diff = vector.subtract(pos,pos2)
if diff.x < 0.5 and diff.x > -0.5 and diff.z < 0.5 and diff.z > -0.5 do
Code: Select all
diff = vector.abs(vector.subtract(pos,pos2))
if diff.x < 0.5 and diff.z < 0.5 then
Code: Select all
function vector.maxnorm(v)
return math.max(math.abs(v.x), math.max(math.abs(v.y), math.abs(v.z)))
end
Code: Select all
norm = vector.maxnorm(vector.multiply(vector.subtract(pos, pos2), {x=2, y=0, z=2}))
if norm < 1 then
Yes that is very good, but it's not modular as you can't recover the actual value of Y as it was before maxnorming it, but that would be a nice function to haveHume2 wrote:This can be actually done even easier by using the maximum norm:Then it reduces to:Code: Select all
function vector.maxnorm(v) return math.max(math.abs(v.x), math.max(math.abs(v.y), math.abs(v.z))) end
Code: Select all
norm = vector.maxnorm(vector.multiply(vector.subtract(pos, pos2), {x=2, y=0, z=2})) if norm < 1 then
This calculates the Eucleidan distance, not the maximum norm distance. Please, read the OP toughly to see what the vector.abs actually does.AspireMint wrote:what about vector.distance(p1, p2) < 0.5
Well I see a lot of people saying this is redundant with the vector.apply function, but, as they say that, we also have:GreenDimond wrote:vector.apply(v, math.abs) but ok.
Code: Select all
function vector.floor(v)
return {
x = math.floor(v.x),
y = math.floor(v.y),
z = math.floor(v.z)
}
end
function vector.round(v)
return {
x = math.floor(v.x + 0.5),
y = math.floor(v.y + 0.5),
z = math.floor(v.z + 0.5)
}
end
function vector.add(a, b)
if type(b) == "table" then
return {x = a.x + b.x,
y = a.y + b.y,
z = a.z + b.z}
else
return {x = a.x + b,
y = a.y + b,
z = a.z + b}
end
end
Code: Select all
vector.round(v)
Code: Select all
vector.apply(v, function(x) return(math.floor(x + 0.5)) end)
Code: Select all
vector.add(a, b)
Code: Select all
local new_vector = {x=a.x+b.x,y=a.y+b.y,z=a.z+b.z}
Code: Select all
v = {x=5,y=1,z=4}
Code: Select all
v = vector.new(5,1,4)
Code: Select all
vector.abs(v)
Users browsing this forum: No registered users and 10 guests