Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
dot() vs cos()
S1mon
Member Posts: 3,046 PRO
@ilya_baran
I'm digging through the code for Bridging curve, and there are several places where dot products are used on normalized vectors. It seems like cosine on the angle between the (non normalized) vectors would yield the same result.
Is this is done for speed?
approachSpeed += dot(side1.tangent, positionDiffNormalized) - 1;
Is this is done for speed?
0
Comments
Edit: @ilya_baran reminded me that also u⋅v = ux*vx + uy*vy + uz*vz.
I figured it was something like that.
I assume these days that trig functions are more optimized with look-up tables and interpolation or some other types of clever numerical methods. But yes, much slower than a few multiplies and adds. There’s also the extra effort to get the length of vectors in order to normalize them.
I’m also curious how much overhead is there in FeatureScript to call functions. When I look at the source for some of the basic functions, there are ones which are only a few lines of code. Certainly using functions like that can make things much cleaner and easier to code, but I wonder when it would make sense (for performance reasons) to put some of these bits of code inline instead of calling a function.