Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / [DBPro 7.7] dot product vector3 error

Author
Message
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 26th Jul 2013 14:31
Whilst creating some new features for Forester Pro (a tree creator for DBPro) I've encountered an interesting error with dot product vector3(). The following will return a -1.#IND sometimes if the two vectors are parallel but in opposite directions (but not in every case). Neither vector is zero length.



The simple, if messy, solution is to catch the value since it should be 180.0.



Took me ages to work out what was happening.


http://www.hptware.co.uk/forester.htm

GrumpyOne - the natural state of the programmer

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Jul 2013 16:59 Edited at: 26th Jul 2013 17:21
Yes, that is an unhelpful error.

I'm surprised no-one has spotted it before. Have you checked?

Edit I should have added that your heading might be misleading. The dot product command seems to return the correct value so it's not clear what is bugged. For example, the following code prints out the argument of the acos command when it returns the wrong answer



yet the following code works perfectly:



Certainly annoying whatever the cause.

Edit2 A bit of experimenting suggests the problem is numerical inaccuracies in the division calculations. In other words, your calculation which should lie in the range -1 to +1 might by accident lie outside that range by a small amount. Try this to see what I mean:



That is not a bug in my opinion - it's just an example of the standard limitations of numerical precision that you need to watch out for as a programmer.
Le Verdier
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 26th Jul 2013 18:20 Edited at: 26th Jul 2013 22:21
Do you want the angle on the full circle ???(180/-180)

Maybe try something like this:





Edit
This don't give on the full circle, another axis need to be defined

Silverman
19
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 28th Jul 2013 19:53
Hi,

to test a value #IND or #INF you can try this way:



You calculate an angle between two 3D vectors, you have normalized before performing the dot product?

DirectX 9.0c (February 2010)/ DBClassic v1.20
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jul 2013 23:36
It's better to avoid the problem in the first place.

Login to post a reply

Server time is: 2026-06-06 15:55:13
Your offset time is: 2026-06-06 15:55:13