First time here? Check out the FAQ!

Ask Your Question
1

Basic vector functions in Sage

asked 12 years ago

paldepind gravatar image

updated 10 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 12 years ago

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)
0
sage: u.dot_product(w)
0
Preview: (hide)
link

Comments

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 ( 12 years ago )

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 ( 12 years ago )

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

paldepind gravatar imagepaldepind ( 12 years ago )

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/.

kcrisman gravatar imagekcrisman ( 12 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 29,615 times

Last updated: Apr 25 '12