Skip to content

Creating a spring between two points #84

Answered by jimy-byerley
GenieTim asked this question in Q&A
Discussion options

You must be logged in to vote

Hello these was few mistakes in your previous code samples, but of course such thing is easily doable in madcad ;)

best approach

The best way (most readable and efficient) in madcad is using a special constructor of quat:

quat(dir1, dir2)  # compute the quaternion rotating from direction 1 to direction 2

As the spring generated by for instance coilspring_tension is oriented toward Z, we need to rotate it toward b-a

orient = quat(Z, b-a)

As the spring is generated centered around zero, we need to translate it to the midpoint between a and b

pos = (b + a) / 2

Now, orient and pos cannot be combined together (quat and vec3), so we need to cast them to transformation matrices so we can use the…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by GenieTim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants