3D Vector OpenSCAD Library
by thingiverse, published
This is a library for manipulating and visualizing 3D vectors in OpenSCAD. It has basic functions like crossProduct_3DVector() and magnatude_3DVector() as well as some more complex functions to test vector angles and rotate one vector towards another vector.
Check out the instructions tab to see more detail.
To use it in your own project, download the .scad and put it in your openscad library folder or in the same folder as the project you are using it in. Then at the top of your script just type :
We've also included this in Customizer! Include it in your customizers by typing:
Here'Âs a full list of the functions and modules included:
give this function a 3D vector in [x,y,z] format and it will return the length of that vector
function angleBetween_3DVector(u, v)
give this function two 3D vectors in [x,y,z] format and it will return the angle, in degrees, between them
give this function a 3D vector in [x,y,z] format and it will return a vector that points in the same direction but with a length of 1
function dotProduct_3DVector(u, v)
give this function two 3D vectors in [x,y,z] format and it will return the dot product of those vectors
function crossProduct_3DVector(u, v)
give this function two 3D vectors in [x,y,z] format and it will return the cross product of those vectors
function rotMatrix_3DVector(axis, angle)
give this function a 3D vectors in [x,y,z] format for axis and an angle in degrees and it will return a rotation matrix for the axis-angle rotation
function rotAxisAngle_3DVector(vec, axis, angle)
give this function an initial 3D vector and a 3D vector for the axis in [x,y,z] format, and an angle in degrees and it will return the rotated vector
function trackTo_3DVector(cur, tar, influence)
give this function an initial 3D vector and a target 3D vector in [x,y,z] format, then give it an influence between 0 and 1 and it will return an interpolated vector between the two vectors according to the influence
function random_3DVector(seed = undef)
calling this function without any parameters will return a random 3D vector. pass it a seed value to get the same "random" vector each time
module drawArrow_3DVector ( vector = [10, 10, 10], root = [0, 0, 0], color_from_magnatude = true, magnatude_range = 100, radius_from_magnatude = true, manual_radius = 1, res = 16 )
this module will draw a colored arrow to represent a 3D Vector.
root controls where the vector starts from.
magnatude_range defines the vector length that will result in a purple arrow. Vectors approaching 0 length will be red.
radius_from_magnatude controls if the arrow gets fatter when it is longer.
manual_radius controls the radius if radius_from_magnatude is set to false.
res is the number of facets around the arrow.
module drawArrowChain_3DVector ( my_vectors = [[10,10,10],[-10,10,10]], root = [0, 0, 0], iterations_left )
this module will recursively draw a chain of colored arrows end to end to represent a list of 3D Vectors.
root controls where the vector chain starts from.
iterations_left controls how many more recursions will occur, this parameter will self populate and only needs to be exposed because of how recursion works in OpenSCAD. Don'Ât set this unless you have a good reason to.
Liked ByView All
Give a Shout Out
3D Vector OpenSCAD Library by thingiverse is licensed under the Creative Commons - Attribution license.
What does this mean?
- You must attribute (give credit) to the creator of this Thing.
- Remixing or Changing this Thing is allowed.
- Commercial use is allowed.
We're sure thingiverse would love to see what you've printed. Please document your print and share a Make with the community.
To post a Make simply visit this Thing again and click I Made One to start uploading your photo. It’s even easier to post a Make via the Thingiverse Mobile app (available via Google Play and Apple App Store).