Oscar makes a good point here:
> Conceptually this is a bit muddled though as it conflates vectors with
> points. Formally what is wanted here is to evaluate a scalar field at a point
> represented by a particular position vector wrt some reference frame. I don't
> know if the vector module has the concept of a point as opposed to a vector.
It turns out sympy.vector does indeed have a Point class. It occurs to me that
I could also dot with each basis vector. Both of these handle the case of a
zero-valued component without introducing an if clause to the list
comprehension (a problem with my original example, as Davide pointed out).
But as far as I can tell, there’s no way to get the coordinates in a format
compatible with subs, so however you get the components you still end up having
to zip them with the base vectors from CoordSys3D. Here are three conceptually
more pleasing ways to get a tuple of components:
In [1]: import sympy
In [2]: import sympy.vector
In [3]: R3 = sympy.vector.CoordSys3D("R3")
In [4]: t = sympy.Symbol("t", real=True)
In [5]: g = t * R3.i - t**2 * R3.j - 0 * R3.k
In [6]: # Three different ways to get the components as a tuple:
In [7]: R3.origin.locate_new(‘P', g).express_coordinates(R3) # Using Point
Out[7]: (t, -t**2, 0)
In [8]: tuple(b.dot(g) for b in R3.base_vectors()) # dot product with each basis
Out[8]: (t, -t**2, 0)
In [9]: tuple(g.to_matrix(R3))
Out[9]: (t, -t**2, 0)
If I were just making stuff up, it would be great if there were operations to
(a) get the point at the end of a vector given a starting point and (b) convert
a point to a dictionary or tuple in a format that subs is happy to consume. So
something like:
g.to_point(R3.origin).to_dict(R3)
But even if we just had (b) we could write
R3.origin.locate_new(‘P', g).to_dict(R3)
Seems a shame to keep passing the coordinate system, but Point doesn’t look
like it remembers it.
/rdj
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/73A0AD28-CA29-4D87-923D-213355CDD1C6%40gmail.com.