AllenDowney / ModSimPy

Text and supporting code for Modeling and Simulation in Python
https://allendowney.github.io/ModSimPy/
MIT License
835 stars 1.77k forks source link

Vector weirdness #17

Closed Bogidon closed 5 years ago

Bogidon commented 6 years ago

Haven't dived too deeply into this, but I'm getting the feeling it isn't the intended behavior. There's a lot of weirdness that happens when multiplying a Pint Quantity by a modsim Vector(Quantity).

For example, this produces the expected result: 11-29-2017-03 55 13

however accessing x or y produces an error:

distance_vector.x
# -> Neither Quantity object nor its magnitude ([ 0.5547002   0.83205029]) has attribute 'x'

here's a workaround:

acc = 1 * UNITS.m/UNITS.second**2 
acc = (acc.m * Vector(2,3).hat()) * acc.units
acc.x
# -> 0.5547001962252291 meter/second**2 :)

Unrelated, there's a weird edge case that brakes Pint's TeX formatting: 11-29-2017-03 57 09

Looks like there's some kind of superscript formatting going on in the TeX source? Might be a bug on Pint's end.

AllenDowney commented 6 years ago

Thanks for letting me know (and sorry I didn't notice this issue sooner!). This one is hard to fix. I will have to think about it...

AllenDowney commented 5 years ago

Yeah, this is really hard to fix. I've explained it better in the book and the documentation. That might be the best I can do.