mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-27 15:29:41 +00:00
add vector_perp
This commit is contained in:
parent
cbe55c8514
commit
cee36c13f2
1 changed files with 20 additions and 0 deletions
20
vectors.scad
20
vectors.scad
|
@ -343,6 +343,26 @@ function vector_bisect(v1,v2) =
|
|||
) v3;
|
||||
|
||||
|
||||
// Function: vector_perp()
|
||||
// Synopsis: Returns component of a vector perpendicular to a second vector
|
||||
// Topics: Vectors, Math
|
||||
// Usage:
|
||||
// perp = vector_perp(v,w);
|
||||
// Description:
|
||||
// Returns the component of vector w that is perpendicular to vector v. Vectors must have the same length.
|
||||
// Arguments:
|
||||
// v = reference vector
|
||||
// w = vector whose perpendicular component is returned
|
||||
// Example(2D): We extract the component of the red vector that is perpendicular to the yellow vector. That component appears in blue.
|
||||
// v = [12,6];
|
||||
// w = [13,22];
|
||||
// stroke([[0,0],v],endcap2="arrow2");
|
||||
// stroke([[0,0],w],endcap2="arrow2",color="red");
|
||||
// stroke([[0,0],vector_perp(v,w)], endcap2="arrow2", color="blue");
|
||||
function vector_perp(v,w) =
|
||||
assert(is_vector(v) && is_vector(w) && len(v)==len(w), "Invalid or mismatched inputs")
|
||||
w - w*v*v/(v*v);
|
||||
|
||||
|
||||
// Section: Vector Searching
|
||||
|
||||
|
|
Loading…
Reference in a new issue