-
|
In ISQ This seems like a bug, because my understanding is that the HEP system should model a similar but independent system to ISQ. I would therefore expect changing namespace from I would like to know if there is any rationale behind this decision. This becomes an issue when dealing with vectors, because if I wanted to construct a velocity from a speed and a direction, I would do (I don't know if there is a better approach) const my_vector_type my_direction = {std::sin(1.0)*std::sin(2.0), std::sin(1.0)*std::cos(2.0), std::sin(1.0)};
const quantity my_speed = speed(1.0*m/s);
const quantity my_velocity = quantity_cast<velocity>(my_speed*my_direction);This works just fine using the const quantity my_velocity
= quantity(my_speed.numerical_value_in(decltype(my_speed)::unit)*my_direction*velocity[decltype(my_speed)::unit])But this is horrible to write and abandons the compile time safety of the units, so surely it cannot be the intended approach. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Hi @sebsassi 👋 Thanks for using the library. You're probably the first confirmed HEP user 😉 If you're willing, I'd love an Usage Experience report, now or once you've settled in. First, sorry for the late reply. When you submitted this, I was in the middle of implementing polar and spherical vector facades, which suit your use case perfectly. I thought I would finish it sooner, but it required more infrastructure work than I initially expected (we got the Yes, in HEP However, the direction you'd probably want is not the A couple of notes on the example itself:
As stated above, over the last few days, I've been working on polar/spherical vector facades. With them, your example is just a magnitude and two angles, and you get a proper velocity vector with no cast and no hand-written trig: const quantity my_speed = isq::speed(1.0 * m / s);
const utility::spherical_vector v_spherical{my_speed, 1.0 * rad, 2.0 * rad}; // speed + inclination(θ from +z) + azimuth(φ from +x)
// a genuine velocity vector — no quantity_cast, no character crossing
const quantity<isq::velocity[m / s], utility::cartesian_vector<double, 3>> v_cartesian = v_spherical.to_cartesian();The magnitude stays a |
Beta Was this translation helpful? Give feedback.
Thanks for the detailed follow-up.
Please note that my spherical vectors are only facades and they do not provide all the arithmetic exactly to prevent this noise. You need to convert to a Cartesian vector once and stay there as long as you want. For a direction that is already Cartesian, like your orbit case, you should not reach for spherical vectors at all.
This turned out to be a real bug on our side, and I have fixed it (should be online in the Compiler Explorer tomorrow). Scaling a Cartesian vector by a …