Skip to content

Commit 7dea63c

Browse files
committed
fix vector_arrowsize
1 parent 752f44c commit 7dea63c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

docs/src/users_guide/plotting_the_bloch_sphere.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ At the end of the last section we saw that the colors and marker shapes of the d
195195
| `b.sphere_alpha` | Transparency of sphere surface | `"#FFDDDD"` |
196196
| `b.vector_color` | Colors for vectors | `["green", "#CC6600", "blue", "red"]` |
197197
| `b.vector_width` | Width of vectors | `0.025` |
198-
| `b.vector_arrowsize` | Arrow size parameters as `[head_length, head_width, stem_width]` | `[0.07, 0.08, 0.08]` |
198+
| `b.vector_arrowsize` | Scales the size of the arrow head. The first two elements scale the radius (in `x/y` direction) and the last one is the length of the cone. | `[0.07, 0.08, 0.08]` |
199199
| `b.view` | Azimuthal and elevation viewing angles in degrees | `[30, 30]` |
200200
| `b.xlabel` | Labels for x-axis | `[L"x", ""]` (``+x`` and ``-x``) |
201201
| `b.xlpos` | Positions of x-axis labels | `[1.2, -1.2]` |

ext/QuantumToolboxMakieExt.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,15 @@ Scales vectors appropriately and adds `3D` arrow markers.
661661
"""
662662
function _plot_vectors!(b::Bloch, lscene)
663663
isempty(b.vectors) && return nothing
664+
665+
arrow_head_length = b.vector_arrowsize[3]
664666
for (i, v) in enumerate(b.vectors)
665667
color = get(b.vector_color, i, RGBAf(0.2, 0.5, 0.8, 0.9))
666-
vec = 0.92 * Vec3f(v...) # multiply by 0.92 so that the point edge of the arrow represents the actual position
668+
nv = norm(v)
669+
(arrow_head_length < nv) || throw(ArgumentError("The length of vector arrow head (Bloch.vector_arrowsize[3]=$arrow_head_length) should be shorter than vector norm: $nv"))
670+
671+
# multiply by the following factor makes the end point of arrow head represent the actual vector position.
672+
vec = (1 - arrow_head_length / nv) * Vec3f(v...)
667673
arrows!(
668674
lscene,
669675
[Point3f(0, 0, 0)],

src/visualization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ A structure representing a Bloch sphere visualization for quantum states. Availa
102102
103103
- `vector_color::Vector{String}`: Colors for vectors
104104
- `vector_width::Float64`: Width of vectors
105-
- `vector_arrowsize::Vector{Float64}`: Arrow size parameters as `[head_length, head_width, stem_width]`
105+
- `vector_arrowsize::Vector{Float64}`: Scales the size of the arrow head. The first two elements scale the radius (in `x/y` direction) and the last one is the length of the cone.
106106
107107
## Layout properties
108108

0 commit comments

Comments
 (0)