@qbead/bloch-sphere
@qbead/bloch-sphere / BlochSphere
Class: BlochSphere
Defined in: src/bloch-sphere.ts:87arrow-up-right
A Bloch Sphere Widget
This class is a wrapper around the THREE.js WebGLRenderer and CSS2DRenderer to create a Bloch sphere visualization.
It provides methods to add and remove objects from the scene.
It must be attached to a parent element in the DOM to be visible. It will automatically resize to fit the parent element.
To resize on window resize, you can call the resize method in the window resize event listener.
Copy import { BlochSphere } from ' bloch-sphere '
const blochSphere = new BlochSphere ( {
fontSize : 1.25 ,
} )
blochSphere . attach ( document . body )
window . addEventListener (
' resize ' ,
() => {
blochSphere . resize ()
},
{ passive : true }
)
// create a qubit display
const qubit = new QubitDisplay ( BlochVector . fromAngles ( 1 , 0 ))
// add the qubit to the Bloch sphere
blochSphere . add ( qubit ) new BlochSphere (options?): BlochSphere
Defined in: src/bloch-sphere.ts:97arrow-up-right
Parameters
Returns
BlochSphere
Get Signature
get showGrid (): boolean
Defined in: src/bloch-sphere.ts:165arrow-up-right
Returns
boolean
Set Signature
set showGrid (value): void
Defined in: src/bloch-sphere.ts:169arrow-up-right
Parameters
Returns
void
add (item): void
Defined in: src/bloch-sphere.ts:173arrow-up-right
Parameters
Returns
void
attach (parent?): void
Defined in: src/bloch-sphere.ts:202arrow-up-right
Attaches the widget to a parent element
Must be called to make the widget visible.
Parameters
Returns
void
clearPlot (): void
Defined in: src/bloch-sphere.ts:186arrow-up-right
Removes all objects from the plot
This will not remove the grid or the sphere.
Returns
void
dispose (): void
Defined in: src/bloch-sphere.ts:467arrow-up-right
Performs cleanup and disposes everything contained in the widget
Returns
void
getCameraAngles()
getCameraAngles (): [number, number]
Defined in: src/bloch-sphere.ts:345arrow-up-right
Get current camera angles as [theta, phi]
Returns
[number, number]
getCameraBlochVector()
getCameraBlochVector (): BlochVector
Defined in: src/bloch-sphere.ts:353arrow-up-right
Get the Bloch vector pointing from origin to camera
Returns
BlochVector
getCameraZoom()
getCameraZoom (): number
Defined in: src/bloch-sphere.ts:338arrow-up-right
Get current camera zoom level
Returns
number
interactivity()
interactivity (options?): InteractivityOptions
Defined in: src/bloch-sphere.ts:429arrow-up-right
Control user interactivity with the camera
Parameters
boolean | InteractivityOptions
Interactivity options or boolean to enable/disable all interactions
Returns
InteractivityOptions
Current interactivity state if no arguments provided
remove (item): void
Defined in: src/bloch-sphere.ts:177arrow-up-right
Parameters
Returns
void
render (): void
Defined in: src/bloch-sphere.ts:231arrow-up-right
Renders the scene
This is called automatically in the animation loop unless that loop is stopped.
Returns
void
resize (width?, height?): void
Defined in: src/bloch-sphere.ts:214arrow-up-right
Resizes the widget to fit the parent element
Optionally, you can specify the width and height to resize to.
Parameters
Returns
void
scale (size): void
Defined in: src/bloch-sphere.ts:193arrow-up-right
Rescales the sphere
Parameters
Returns
void
setCameraAngles()
setCameraAngles (theta, phi, duration?, easing?): void | Promise<void>
Defined in: src/bloch-sphere.ts:391arrow-up-right
Set camera position using spherical coordinates
Parameters
Returns
void | Promise<void>
setCameraState()
setCameraState (cameraState, duration?, easing?): void | Promise<void>
Defined in: src/bloch-sphere.ts:363arrow-up-right
Set camera state (unified method)
Parameters
Returns
void | Promise<void>
setCameraToBlochVector()
setCameraToBlochVector (blochVector, duration?, easing?): void | Promise<void>
Defined in: src/bloch-sphere.ts:374arrow-up-right
Position camera such that the given Bloch vector points directly at camera
Parameters
Returns
void | Promise<void>
setCameraZoom()
setCameraZoom (zoomLevel, duration?, easing?): void | Promise<void>
Defined in: src/bloch-sphere.ts:409arrow-up-right
Set camera zoom level
Parameters
Returns
void | Promise<void>
setOptions (options?): void
Defined in: src/bloch-sphere.ts:113arrow-up-right
Parameters
Returns
void
start (): void
Defined in: src/bloch-sphere.ts:244arrow-up-right
Starts the animation loop
Automatically started when the widget is attached to a parent element.
This will call the render method automatically.
Returns
void
stop (): void
Defined in: src/bloch-sphere.ts:255arrow-up-right
Stops the animation loop
This will stop the render loop
Returns
void