Ask Your Question

Basic vector functions in Sage

asked 2012-04-25 00:43:34 -0500

paldepind gravatar image

updated 2015-01-14 04:00:17 -0500

FrédéricC gravatar image

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 flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2012-04-25 06:08:39 -0500

kcrisman gravatar image

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)
sage: u.dot_product(w)
edit flag offensive delete link 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.

paldepind gravatar imagepaldepind ( 2012-05-01 06:03:47 -0500 )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.

kcrisman gravatar imagekcrisman ( 2012-05-01 15:36:21 -0500 )edit

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

paldepind gravatar imagepaldepind ( 2012-05-02 22:42:27 -0500 )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 for how to start contributing to Sage directly, or you could just upload code for an algorithm to a ticket you created on

kcrisman gravatar imagekcrisman ( 2012-05-03 03:36:22 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-04-25 00:43:34 -0500

Seen: 9,576 times

Last updated: Apr 25 '12