Jump to content

Vector Comparison


Ne0 Nirvana
 Share

You are about to reply to a thread that has been inactive for 3496 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi guys,

I am trying to compare between two vectors variable and it seems like the editor giving me type mismatch error for this only.

May I know what is the issue? (openPos) is vector type with global definition : vector openPos;

if(llGetPos() < openPos)

 The weird part is that, if i do below line, it will work

if(llGetPos() == openPos)
//and below line as well
if(llGetPos() != openPos)

 

Link to comment
Share on other sites

I'm not sure I can properly explain the problem, other than saying that it's difficult to evaluate vectors through an if because they comprise 3 parts, X, Y and Z. Is lowX 'less' than highY? Complicated!

Try:-

if(llVecDist(llGetPos(),openPos) < 0)

 llVecDist changes both vectors into type float (distance between two vectors), which is then more easily evaluated.

In an if statement:-

  • == and != are comparative tests
  • > and < are quantative tests
Link to comment
Share on other sites


Freya Mokusei wrote:

I'm not sure I can properly explain the problem, other than saying that it's difficult to evaluate vectors through an if because they comprise 3 parts, X, Y and Z. Is lowX 'less' than highY? Complicated!

Try:-
if(llVecDist(llGetPos(),openPos) < 0)

 
changes both vectors into type float (distance between two vectors), which is then more easily evaluated.

Hmm, yeah, since there is 3 value in the vector type, and the only value that changed actually just the Z value. I put it in the timer to increase (the llGetPos) until it reach the same as the openPos (Z value only). The main problem with using the simple code below 

if (llGetPos == openPos)

 is that it will never stop even the value is already similar.

I have tried your idea but it did not work. Do you think Its a good idea to take out the Z value from that vector and compare it? 

Link to comment
Share on other sites

It's possible my mental compiling abilities are on the fritz. Maybe it should be > (Greater than)?

Check the output of llVecDist by dumping to llOwnerSay, and determine what test you need to use to get this to evaluate properly. I'm 99.9% sure this is the function you need, but I have no idea what you're trying to do with it.

Link to comment
Share on other sites

It really depends on what you're trying to measure.   If all you want to know if the object's height is less than that of openPos, then test for  something like

vector temp = llGetPos();if (temp.z< openPos.z){//do something}

 If you describe what you're trying to make, it might help to clarify what you need the code to do.

 
Link to comment
Share on other sites

Because the "<" operator is not defined for vectors. Why would it be, how can one point in space be less than another point in space. Of course it can be the same == or different !=

To make a comparison you would have to write your own function to compare the X,Y and Z of the two vectors in a way that makes sense in your circumstances, such as:

 

integer vless(vector A, vector B)

{

if(A.X < B.X) return TRUE;

if(A.Y < BY) return TRUE;

ifA.Z < B.Z) return TRUE;

return FALSE;

}

Link to comment
Share on other sites


Innula Zenovka wrote:

It really depends on what you're trying to measure.   If all you want to know if the object's height is less than that of openPos, then test for  something like
vector temp = llGetPos();if (temp.z< openPos.z){//do something}

 If you describe what you're trying to make, it might help to clarify what you need the code to do.
 

ahh, for this solution, I have to assign the vector (llGetPos() ) to another vector variable?

Just now i did this but I do it directly :

if(llGetPos().z < openPos.z){}

 but it just giving me sytax error.

*update : ok, stupid me, this is the basic error that I did, it's a function that's returning the whole vectors value, so, obviously what I did was totally wrong. But, I think i will stick to the llVecDist() function since I do not have to define another 1 variable just to get the height. :D

Link to comment
Share on other sites


Freya Mokusei wrote:

It's possible my mental compiling abilities are on the fritz. Maybe it should be > (Greater than)?

Check the output of llVecDist by dumping to llOwnerSay, and determine what test you need to use to get this to evaluate properly. I'm 99.9% sure this is the function you need, but I have no idea what you're trying to do with it.

Thanks for the code, it work, i just tune it to be 

llVecDist(llGetPos(),openPos) <2

 and now going through for the scale

Link to comment
Share on other sites


Dora Gustafson wrote:

You can't compare vector sizes like you do

You can compare vector magnitudes:
if( llVecMag(llGetPos()) < llVecMag( openPos))

 If that will do is not easy for me to say when I don't know what you want to do

:smileysurprised:
:)
:smileyvery-happy:

 

Thanx Dora,

actually, what im trying to do is that I am using a timer to increase the Z pos for the mesh until it became == or < with the default vector for Pos I have, and will scale the Y-axis scale until it == or < with the default vector for scale I have assigned.

so, in the timer, I just need to put this if statement to make it stop when it reach the default value.

if(llVecDist(llGetPos(),openPos) <2 && //for scale comparison now)

 

Link to comment
Share on other sites


Ne0 Nirvana wrote:

*update : ok, stupid me, this is the basic error that I did, it's a function that's returning the whole vectors value, so, obviously what I did was totally wrong. But, I think i will stick to the llVecDist() function since I do not have to define another 1 variable just to get the height.
:D

 Be careful, though.;   llVecDist() returns a non-negative float that represents the distance between the two positions.   If llVecDist(myPos,targetPos) returns 5.0 you have no way of knowing where myPos is in relation to targetPos, other than that it's a point on a sphere with a radius of 5 metres with targetPos as the centre.

Really, if you want to know how far myPos is above or below targetPos, and aren't interested in where it is on the x or y axis (either the region's axes -- north/south/east/west -- or targetPos' axes (left, right, in front of, behind) then measuring myPos.z and comparing it with targetPos.z is the way to do it.

Your way -- using llVecDist() -- may work in very specific circumstances, but is also going to return TRUE in a lot of cases where that's not what you meant.  

Unless you really do just want to know how far myPos is from targetPos, use myPos.z.

 
 
 
Link to comment
Share on other sites


Innula Zenovka wrote:


Ne0 Nirvana wrote:

*update : ok, stupid me, this is the basic error that I did, it's a function that's returning the whole vectors value, so, obviously what I did was totally wrong. But, I think i will stick to the llVecDist() function since I do not have to define another 1 variable just to get the height.
:D

 Be careful, though.;  
returns a non-negative float that represents the distance between the two positions.   If llVecDist(myPos,targetPos) returns 5.0 you have no way of knowing where myPos is in relation to targetPos, other than that it's a point on a sphere with a radius of 5 metres with targetPos as the centre.

Really, if you want to know how far myPos is above or below targetPos, and aren't interested in where it is on the x or y axis (either the region's axes -- north/south/east/west -- or targetPos' axes (left, right, in front of, behind) then measuring myPos.z and comparing it with targetPos.z is the way to do it.

Your way -- using llVecDist() -- may work in very specific circumstances, but is also going to return TRUE in a lot of cases where that's not what you meant.  

Unless you really do just want to know how far myPos is from targetPos, use myPos.z.
 
 
 

Agree strongly with this.

I had assumed the OP was building something like a door, that works on a toggle. In this limited use-case llVecDist may be suitable, but other solutions would give more flexible output.

Link to comment
Share on other sites

There are 2 problems:

1:  ">" and "<" is not possible with vectors, that was already explained. Only "==" and "!=" are possible.

2: "==" and "!=" don't work. vectors consist of floats and you can not compare floats in a reliable way.

Example:

You set a prim to the position <100,100,100> Then you compare the result and it's equal - the prim is at <100,100,100>.
Great :)

Now we have a sim restart and you compare again. Oh wonder - it's not equal anymore. The position is <100.0001, 99.9999, 100.00001> for example. Not equal. sript will take actions for the case "!=" which is most probably not what you wanted.

This is the difference between theory and SL !!!

I compare 2 vectors like that: llVecDist(v1, v2)<0.005;

TRUE means "==" and FALSE means "!=" - works fine for me but what you need to do depends on the single case.

 

Link to comment
Share on other sites


Nova Convair wrote:

There are 2 problems:

1:  ">" and "<" is not possible with vectors, that was already explained. Only "==" and "!=" are possible.

2: "==" and "!=" don't work. vectors consist of floats and you can not compare floats in a reliable way.

Example:

You set a prim to the position <100,100,100> Then you compare the result and it's equal - the prim is at <100,100,100>.

Great
:)

Now we have a sim restart and you compare again. Oh wonder - it's not equal anymore. The position is <100.0001, 99.9999, 100.00001> for example. Not equal. sript will take actions for the case "!=" which is most probably not what you wanted.

This is the difference between theory and SL !!!

I compare 2 vectors like that: llVecDist(v1, v2)<0.005;

TRUE means "==" and FALSE means "!=" - works fine for me but what you need to do depends on the single case.

 

hahaha, yeah, this is one of the main prob when im using the '==' because when the value of the Z-axis increase 0.1 by timer, what happened was that there is a time where it increases automatically to 0.11.. for example :

<100,100,100> ---> increase to <100,100,100.1> and in the middle,all of the sudden increased to <100,100,101.01>,<100,100,101.11>.. *notice the 0.01 at the back..im not really sure why does that happened?hahah.  that's why im searching for a method to stop the increment when it reach certain amount..

Link to comment
Share on other sites

 

if(llVecMag(llGetPos()) <= llVecMag(openPos) && llVecMag(llGetScale()) >= llVecMag(openScale))

 

 Ok, thanks alot to you guys for the helpful advices. I have manage to set the comparison for vector using Magnitude.

This work since only 1 axis is changing, never tried if all 3 axis changes.

<3 <3 <3!!

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3496 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...