Loading
thingiverse

3D Vector OpenSCAD Library

by thingiverse Mar 27, 2014
Download All Files

Please Login to Comment

the following code does not seem to line up:

offset_length = 0.71;
offset_height = 0.43;
offset_angle = angleBetween_3DVector([0, 0, 0], [offset_length, 0, offset_height]);

cube(size = [1, 1, 1], center = false);
translate([offset_length, 0, offset_height]) {
    cube(size = [1, 1, 1], center = false);
}

translate([0, 0.125, 1]) 
{
    rotate(a = offset_angle, v = [0, 1, 0])
    {
        color("red")
        {
            cube(size = [1, 1, 1], center = false);
        }
    }
}

smile

btw I needed to update angleBetween_3DVector() since it was throwing an error when starting with [0, 0, 0] so I added some infinitesimal value to both vectors thus lowering the chances of a divide-by-zero error somewhere.

        function angleBetween_3DVector(u, v) = acos(((u+[0.000001, 0.000001, 0.000001]) * (v+[0.000001, 0.000001, 0.000001])) / (magnatude_3DVector(u+[0.000001, 0.000001, 0.000001]) * magnatude_3DVector(v+[0.000001, 0.000001, 0.000001])));

the following lines up correctly though:

    offset_angle = atan2(offset_length, offset_height)

also where is the function 'hsvToRGB'??

in module drawArrow_3DVector there is no option to set the color and color_from_magnitude variable is unused. suggest you change the declaration and color line to the following:

module drawArrow_3DVector
(
vector = [10, 10, 10],
root = [0, 0, 0],
color_from_magnatude = true,
color="black",
magnatude_range = 100,
radius_from_magnatude = true,
manual_radius = 1,
res = 16
)

color((color_from_magnatude?(hsvToRGB(magnatude / magnatude_range * 360,1,1,1)):color))

also it should be spelled magnitude and not magnatude.