Advertisement

vector representation by direction(unit vrctor) - length

Started by January 27, 2003 03:11 AM
3 comments, last by minorlogic 22 years ago
Hi. Do some body ever work with such a representation ? class dl_vector{ vector3 directiron; ( length == 1 ) float Length; }; can be operations like addition - substraction solved fast and without sqrts ? operator +=( dl_vector& v ){ directiron += v; Length = .... ; ???? directiron *= Length/OldLength; }
there are some good tuts at www.myran.com/enilno
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Advertisement
Nothing found there .....
I don''t think it would be very useful for a generic vector. You would be better off to keep the actual vector with a length that may or may not be there. Then seperately have a unit vector type. When a vector is constructed without an explicit length the length is set to something like NaN. The first time the length is requested you save it and in subsequent requests you return the previously calculated value. Whenever operations change the length in an unpredictable manner you set it back to NaN. That saves you from having to worry about how many times you calculate the magnitude of the same vector. I still don''t think it would be good for a generic vector since you are adding operations into everything that modifies the vector. It might be reasonable when you have a fairly static vector whose magnitude is used all over the place.

As for your original question, no. You can find the magnitude of the resultant using the law of cosines and the dot product to get the cosine since you have two unit vectors. The cheapest way to find the direction though is to multiply both unit vectors by their length and add them together. You can''t use the law of sines without an expense operation to find the sine, i.e. square root, arccosine, etc. Even given the sine between the resultant and one of the vectors it is going to be expense to actually get that into a unit vector pointing the right way. That is the reason I say you would be better off not using a unit vector. If it isn''t a unit vector then you save six multiplies on an add/subtract. Within most situations where a unit vector eliminates division by the magnitude you could care less about the magnitude which is why you are dividing by it.
Keys to success: Ability, ambition and opportunity.
LilBudyWizer
Thanks very much , i tryed to do it but it still take many calc, i have no see the way to do it faster.

The fast is your proposition about remember of last value and validate it.
Usualy i do it such way ... and (seems) will do.

This topic is closed to new replies.

Advertisement