Notifications
Clear all

[Closed] Acos problem


obj1 = $obj1
obj2 = $obj2
obj = $obj
V1 = obj1.transform.pos - obj.transform.pos
V2 = obj2.transform.pos - obj.transform.pos
N1 = normalize V1
N2 = normalize V2
Ang = acos (dot N1 N2)

Hello! I use this code and its working well in most case. But some times Ang return -1.#IND – it makes a mess in results of function based on Ang value.

How to avoid/fix it?

2 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

check infinity of acos result using bit.isFinite

denisT: thank you, I will try.

meanwhile I get good result with another method of calc Ang (oroginal fn by VG)


fn getalfa p1 p2 p3 =     (
    v1=normalize(p2-p1)
    v2=normalize(p3-p1)
    z = cross v1 v2
    len = length (z)
    return atan2 len (dot v1 v2)
    )