# 3D Vector OpenSCAD Library

## by thingiverse, published

0
Share

1526
189

Report Thing as Inappropriate
## Description

This is a library for manipulating and visualizing 3D vectors in [OpenSCAD](http://www.openscad.org). 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](http://www.thingiverse.com/thing:279886/#instructions) to see more detail.

Check out the [instructions tab](http://www.thingiverse.com/thing:279886/#instructions) to see more detail.

1526
189

Report Thing as Inappropriate
## Tags

## License

3D Vector OpenSCAD Library by thingiverse is licensed under the Creative Commons - Attribution license.

## Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.
Print Thing Tag

## Instructions

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 :

`use `

We've also included this in Customizer! Include it in your customizers by typing:

`use `

Here'Âs a full list of the functions and modules included:

`function magnatude_3DVector(v)`

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

`function normalize_3DVector(v)`

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.

`use `

We've also included this in Customizer! Include it in your customizers by typing:

`use `

Here'Âs a full list of the functions and modules included:

`function magnatude_3DVector(v)`

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

`function normalize_3DVector(v)`

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.

Download All Files
(1 kb zip file)

Please Login to Comment