Jump to content

implicit cast


evanrudefx

Recommended Posts

Hi,

What would a better way of writing this be to get rid of the implicit cast warning?

if (@P.y < ch('pthreshold')
    || abs(@v.xyz) < ch('vthreshold'))
    removepoint(0,@ptnum);

I want the absolute value of velocity x,y and z to = my vthreshold value. I get the implicit cast warning because the vthreshold is only a float and not a vector. Any help would be appreciated. As you may know, the expression works as it is now, I just want to get rid of the warning by writing it properly.

 

Thanks

 

Edited by ejr32123
Link to comment
Share on other sites

abs(@v.xyz) < ch('vthreshold')

Did you want to compare each component of your vector individually? There's no good way to do that in one line.

This code compares the absolute value of @v.x to the threshold. The abs() function returns a vector with the absolute values of x, y, and z in it. So, you could do something like distance(abs(@v), {0,0,0}) to find the vector distance to 0 if you wanted a one line comparison. However, if I wanted to compare each of those components I would usually write it out like this:

float t = chf("threshold");
vector abs = abs(@v);

if(abs.x < t || abs.y < t || abs.z < t){
	// code
}

Hope this helps!

  • Thanks 1
Link to comment
Share on other sites

35 minutes ago, dgani said:

abs(@v.xyz) < ch('vthreshold')

Did you want to compare each component of your vector individually? There's no good way to do that in one line.

This code compares the absolute value of @v.x to the threshold. The abs() function returns a vector with the absolute values of x, y, and z in it. So, you could do something like distance(abs(@v), {0,0,0}) to find the vector distance to 0 if you wanted a one line comparison. However, if I wanted to compare each of those components I would usually write it out like this:


float t = chf("threshold");
vector abs = abs(@v);

if(abs.x < t || abs.y < t || abs.z < t){
	// code
}

Hope this helps!

thanks : )

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...