ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 03 May 2012 10:36:22 +0200Basic vector functions in Sagehttps://ask.sagemath.org/question/8924/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.Wed, 25 Apr 2012 07:43:34 +0200https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/Answer by kcrisman for <p>Isn't there any inbuilt 3D vector functions in Sage?</p>
<p>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.</p>
https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?answer=13497#post-id-13497These are all accessible using the "dot" object-oriented notation. See, for example, [this documentation](http://sagemath.org/doc/reference/sage/modules/free_module_element.html?highlight=dot%20product#sage.modules.free_module_element.FreeModuleElement.cross_product), 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
Wed, 25 Apr 2012 13:08:39 +0200https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?answer=13497#post-id-13497Comment by paldepind for <p>These are all accessible using the "dot" object-oriented notation. See, for example, <a href="http://sagemath.org/doc/reference/sage/modules/free_module_element.html?highlight=dot%20product#sage.modules.free_module_element.FreeModuleElement.cross_product">this documentation</a>, from which this example stems.</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19825#post-id-19825Thanks for the explanation. How can I implement these functions in Sage? At least for my own usage.Thu, 03 May 2012 05:42:27 +0200https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19825#post-id-19825Comment by kcrisman for <p>These are all accessible using the "dot" object-oriented notation. See, for example, <a href="http://sagemath.org/doc/reference/sage/modules/free_module_element.html?highlight=dot%20product#sage.modules.free_module_element.FreeModuleElement.cross_product">this documentation</a>, from which this example stems.</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19823#post-id-19823Depends 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/.Thu, 03 May 2012 10:36:22 +0200https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19823#post-id-19823Comment by paldepind for <p>These are all accessible using the "dot" object-oriented notation. See, for example, <a href="http://sagemath.org/doc/reference/sage/modules/free_module_element.html?highlight=dot%20product#sage.modules.free_module_element.FreeModuleElement.cross_product">this documentation</a>, from which this example stems.</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19836#post-id-19836I 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.Tue, 01 May 2012 13:03:47 +0200https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19836#post-id-19836Comment by kcrisman for <p>These are all accessible using the "dot" object-oriented notation. See, for example, <a href="http://sagemath.org/doc/reference/sage/modules/free_module_element.html?highlight=dot%20product#sage.modules.free_module_element.FreeModuleElement.cross_product">this documentation</a>, from which this example stems.</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19832#post-id-19832I 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.Tue, 01 May 2012 22:36:21 +0200https://ask.sagemath.org/question/8924/basic-vector-functions-in-sage/?comment=19832#post-id-19832