Notifications
Clear all

[Closed] compare two vectors

What is the best way to test on whether two vectors match each other or not?


fn do_vectors_match v1 v2 = 
(
	local val = abs (dot (normalize v1) (normalize v2))
	if val == 1.0 or val == 180.0 do return true
	false
)
4 Replies
 lo1

What do you mean by match?

1 Reply
(@jokermartini)
Joined: 10 months ago

Posts: 0

if the vectors are the same

 lo1

Either of these is fine:

fn Point3Equal a b epsilon:0.0001 =
(
	abs(a.x - b.x) < epsilon and
	abs(a.y - b.y) < epsilon and
	abs(a.z - b.z) < epsilon
)

fn Point3Equal a b epsilon:0.0001 =
(
	length (a - b) < epsilon
)

alternatively you can replace the checks in the first one with close_enough

thanks Lo i appreciate the help.