evanrudefx Posted March 21, 2018 Share Posted March 21, 2018 (edited) 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 March 21, 2018 by ejr32123 Quote Link to comment Share on other sites More sharing options...
dgani Posted March 21, 2018 Share Posted March 21, 2018 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! 1 Quote Link to comment Share on other sites More sharing options...
evanrudefx Posted March 21, 2018 Author Share Posted March 21, 2018 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 : ) Quote Link to comment Share on other sites More sharing options...
anim Posted March 22, 2018 Share Posted March 22, 2018 for oneliner: if (min(abs(v@v)) < chf('threshold')) {// code}; or what can be more useful with velocity is to compare the speed if (length(v@v) < chf('threshold')) {// code}; 1 Quote Link to comment Share on other sites More sharing options...
evanrudefx Posted March 22, 2018 Author Share Posted March 22, 2018 Thanks again : ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.