# Basic vector functions in Sage

Isn't there any inbuilt 3D vector functions in Sage?

For instance like a function to get the dot product, cross product or angle between two vectors? Or functions to get the distance from a point to a line? Find the intersections between two lines? Having such functions would be a great help and would greatly increase the speed of my workflow in school.

edit retag close merge delete

Sort by » oldest newest most voted

These are all accessible using the "dot" object-oriented notation. See, for example, this documentation, from which this example stems.

sage: v = vector([1,2,3]); w = vector([0,5,-9])
sage: v.cross_product(v)
(0, 0, 0)
sage: u = v.cross_product(w); u
(-33, 9, 5)
sage: u.dot_product(v)
0
sage: u.dot_product(w)
0

more

I only see cross product and dot product? What about the other things I mentioned? And for instance the distance from a point to a plane? I can't find any of it by searching.

( 2012-05-01 13:03:47 +0200 )edit

I don't think that Sage would include things that one is supposed to do mathematics for. The intersection of two lines would depend greatly on how you represented them, for instance - parametric, as an intersection of planes, as a formula in 2D... Same thing with an angle, which you can get from the cross *or* dot product with inverse trig functions. Of course, many of these would be relatively easy to implement, and we would welcome the addition.

( 2012-05-01 22:36:21 +0200 )edit

Thanks for the explanation. How can I implement these functions in Sage? At least for my own usage.

( 2012-05-03 05:42:27 +0200 )edit

Depends on what you want. For your own usage, you could put the code for such a thing in a .sage file and then have loading that file done automatically by an init.sage file (search for this). For wider distribution, see http://www.sagemath.org/doc/developer/walk_through.html for how to start contributing to Sage directly, or you could just upload code for an algorithm to a ticket you created on http://trac.sagemath.org/sage_trac/.

( 2012-05-03 10:36:22 +0200 )edit