JXG.View3D

Class

3D view inside a JXGraph board.

Creates a new 3D view. Do not use this constructor to create a 3D view. Use JXG.Board#create with type View3D instead.

Attributes

Own

none

Inherited

Members

Own

(private) _lastPos : Object

Description

Store last position of pointer. This is the successor to use evt.movementX/Y which caused problems on firefox

Type
Object
Source
3d/view3d.js, line 221

angles

Description

The Tait-Bryan angles specifying the view box orientation

Source
3d/view3d.js, line 108

az_slide : Slider

Description

Slider to adapt azimuth angle

Type
Slider
Source
3d/view3d.js, line 2890

bank_slide : Slider

Description

Slider to adjust bank angle

Type
Slider
Source
3d/view3d.js, line 2960

bbox3D : array

Description

Bounding box (cube) [[x1, x2], [y1,y2], [z1,z2]] of the 3D view

Type
array
Source
3d/view3d.js, line 186

boxToCam : Array

Description

The 4×4 matrix that maps box coordinates to camera coordinates. These coordinate systems fit into the View3D coordinate atlas as follows.

  • World coordinates. The coordinates used to specify object positions in a JSXGraph scene.
  • Box coordinates. The world coordinates translated to put the center of the view box at the origin.
  • Camera coordinates. The coordinate system where the x, y plane is the screen, the origin is the center of the screen, and the z axis points out of the screen, toward the viewer.
  • Focal coordinates. The camera coordinates translated to put the origin at the focal point, which is set back from the screen by the focal distance.

The boxToCam transformation is exposed to help 3D elements manage their 2D representations in central projection mode. To map world coordinates to focal coordinates, use the JXG.View3D#worldToFocal method.

Type
Array
Source
3d/view3d.js, line 166

defaultAxes : Object

Description

Default axes of the 3D view, contains the axes of the view or null.

Type
Object
Default Value
null
Source
3d/view3d.js, line 103

(private) depthOrdered : Object

Description

An array containing all the elements in the view that are sorted due to their depth order.

Type
Object
Source
3d/view3d.js, line 80

el_slide : Slider

Description

Slider to adapt elevation angle

Type
Slider
Source
3d/view3d.js, line 2925

(private) elementsByName : Object

Description

An associative array / dictionary to store the objects of the board by name. The name of the object is the key and value is a reference to the object.

Type
Object
Source
3d/view3d.js, line 95

focalDist : Number

Description

The distance from the camera to the screen. Computed automatically from the fov property.

Type
Number
Source
3d/view3d.js, line 201

(private) llftCorner : array

Type
array
Source
3d/view3d.js, line 173

(private) matrix3D : Array

Type
Array
Source
3d/view3d.js, line 138

matrix3DRot : Array

Description

The view box orientation matrix

Type
Array
Source
3d/view3d.js, line 118

(private) objects : Object

Description

An associative array containing all geometric objects belonging to the view. Key is the id of the object and value is a reference to the object.

Type
Object
Source
3d/view3d.js, line 73

projectionType : String

Description

Type of projection. Is set in in update().

Type
String
Source
3d/view3d.js, line 207

r : Number

Description

The distance from the camera to the origin. In other words, the radius of the sphere where the camera sits.

Type
Number
Default Value
null
Source
3d/view3d.js, line 194

shift

Description

The translation that moves the center of the view box to the origin.

Source
3d/view3d.js, line 830

(private) size : array

Description

Width and height [w, h] of the 3D view if elevation and azimuth are set to 0.

Type
array
Source
3d/view3d.js, line 180

trackballEnabled : String

Description

Whether trackball navigation is currently enabled.

Type
String
Source
3d/view3d.js, line 213

Inherited

Methods

Own

(private) _azEventHandler(evt)

Controls the navigation in az direction using either the keyboard or a pointer.

Parameters

Name Type Description
evt event

either the keydown or the pointer event

Returns

view

Details

Source
3d/view3d.js, line 1967

(private) _az_elEventHandler(evt)

Controls 2-degree navigation in az direction using pointer.

Parameters

Name Type Description
evt event

the pointer event

Returns

view

Details

Source
3d/view3d.js, line 1903

(private) _bankEventHandler(evt)

Controls the navigation in bank direction using either the keyboard or a pointer.

Parameters

Name Type Description
evt event

either the keydown or the pointer event

Returns

view

Details

Source
3d/view3d.js, line 2078

(private) _elEventHandler(evt)

Controls the navigation in el direction using either the keyboard or a pointer.

Parameters

Name Type Description
evt event

either the keydown or the pointer event

Returns

view

Details

Source
3d/view3d.js, line 2022

(private) _getW0(mat, v2d, d)

We know that v2d * w0 = mat * (1, x, y, d)^T where v2d = (1, b, c, h)^T with unknowns w0, h, x, y. Setting R = mat^(-1) gives 1/ w0 * (1, x, y, d)^T = R * v2d. The first and the last row of this equation allows to determine 1/w0 and h.

Parameters

Name Type Description
mat Array
v2d Array
d Number

Returns

Array

Details

Source
3d/view3d.js, line 1188

(private) _projectToSphere(r, x, y)

Project 2D point (x,y) to the virtual trackpad sphere, see Bell's virtual trackpad, and return z-component of the number.

Parameters

Name Type Description
r Number
x Number
y Number

Returns

Number

Details

Source
3d/view3d.js, line 510

(private) _trackballHandler(evt)

Controls the navigation using either virtual trackball.

Parameters

Name Type Description
evt event

either the keydown or the pointer event

Returns

view

Details

Source
3d/view3d.js, line 2131

(private) _updateCentralProjection() → {Array}

Returns

Type
Array

Details

Source
3d/view3d.js, line 750

animateAzimuth()

Details

Source
3d/view3d.js, line 1744

compareDepth(a, b)

Compares 3D elements according to their z-Index.

Parameters

Name Type Description
a JXG.GeometryElement3D
b JXG.GeometryElement3D

Returns

Number

Details

Source
3d/view3d.js, line 894

create(elementType, parents, attributesopt) → {Object}

Creates a new 3D element of type elementType.

Parameters

Name Type Attributes Description
elementType String

Type of the element to be constructed given as a string e.g. 'point3d' or 'surface3d'.

parents Array

Array of parent elements needed to construct the element e.g. coordinates for a 3D point or two 3D points to construct a line. This highly depends on the elementType that is constructed. See the corresponding JXG.create* methods for a list of possible parameters.

attributes Object <optional>

An object containing the attributes to be set. This also depends on the elementType. Common attributes are name, visible, strokeColor.

Returns

Reference to the created element. This is usually a GeometryElement3D, but can be an array containing two or more elements.

Type
Object

Details

Source
3d/view3d.js, line 255

freeR()

Stop ignoring attribute r. After a call of view3d.setView, view3d.nextView, view3d.previousView, or view3d.setCurrentView this attribute is ignored. Call of view3d.freeR() will end this.

Details

See
Source
3d/view3d.js, line 1794

(private) getCameraDistance()

Get distance from view box center to camera. In other words, the radius of the sphere where the camera sits. Distinguishes between projection tpye 'central' and 'parallel'. Uses the value of attribute 'r'.

Returns

Number

Details

See
Source
3d/view3d.js, line 716

(private) getMesh(func, interval_u, interval_v)

Generate mesh for a surface / plane. Returns array [dataX, dataY] for a JSXGraph curve's updateDataArray function.

Example

var el = view.create('curve', [[], []]);
 el.updateDataArray = function () {
     var steps_u = this.evalVisProp('stepsu'),
          steps_v = this.evalVisProp('stepsv'),
          r_u = Type.evaluate(this.range_u),
          r_v = Type.evaluate(this.range_v),
          func, ret;

     if (this.F !== null) {
         func = this.F;
     } else {
         func = [this.X, this.Y, this.Z];
     }
     ret = this.view.getMesh(func,
         r_u.concat([steps_u]),
         r_v.concat([steps_v]));

     this.dataX = ret[0];
     this.dataY = ret[1];
 };

Parameters

Name Type Description
func Array | function
interval_u Array
interval_v Array

Returns

Array

Details

Source
3d/view3d.js, line 1692

intersectionLineCube(p, dir, r)

Intersect a ray with the bounding cube of the 3D view.

Parameters

Name Type Description
p Array

3D coordinates [w,x,y,z]

dir Array

3D direction vector of the line (array of length 3 or 4)

r Number

direction of the ray (positive if r > 0, negative if r < 0).

Returns

Affine ratio of the intersection of the line with the cube.

Details

Source
3d/view3d.js, line 1408

intersectionPlanePlane(plane1, plane2, d) → {Array}

Parameters

Name Type Description
plane1 Plane3D
plane2 Plane3D
d Number

Right hand side of Hesse normal for plane2 (it can be adjusted)

Returns

of length 2 containing the coordinates of the defining points of of the intersection segment, or false if there is no intersection

Type
Array

Details

Source
3d/view3d.js, line 1459

isInCube(p)

Test if coordinates are inside of the bounding cube.

Parameters

Name Type Description
p array

3D coordinates [[w],x,y,z] of a point.

Returns

Boolean

Details

Source
3d/view3d.js, line 1433

(private) isVerticalDrag()

Check if vertical dragging is enabled and which action is needed. Default is shiftKey.

Returns

Boolean

Details

Source
3d/view3d.js, line 1778

nextView() → {Object}

Changes view to the next view stored in the attribute values.

Returns

Reference to the view.

Type
Object

Details

See
Source
3d/view3d.js, line 1839

(private) pointerDownHandler(evt)

Event handler for pointer down event. Triggers handling of all 3D navigation.

Parameters

Name Type Description
evt event

Returns

view

Details

Source
3d/view3d.js, line 2161

(private) pointerUpHandler(evt)

Event handler for pointer up event. Triggers handling of all 3D navigation.

Parameters

Name Type Description
evt event

Returns

view

Details

Source
3d/view3d.js, line 2278

previousView() → {Object}

Changes view to the previous view stored in the attribute values.

Returns

Reference to the view.

Type
Object

Details

See
Source
3d/view3d.js, line 1860

project2DTo3DPlane(point2d, normal, foot) → {Array}

Project a 2D coordinate to the plane defined by point "foot" and the normal vector normal.

Parameters

Name Type Description
point2d Point
normal Array

Normal of plane

foot Array

Foot point of plane

Returns

of length 4 containing the projected point in homogeneous coordinates.

Type
Array

Details

Source
3d/view3d.js, line 1210

project2DTo3DVertical(point2d, base_c3d) → {Array}

Project a 2D coordinate to a new 3D position by keeping the 3D x, y coordinates and changing only the z coordinate. All horizontal moves of the 2D point are ignored.

Parameters

Name Type Description
point2d Point
base_c3d Array

Returns

of length 4 containing the projected point in homogeneous coordinates.

Type
Array

Details

Source
3d/view3d.js, line 1354

project3DTo2D(x, y, z) → {Array}

Project 3D coordinates to 2D board coordinates The 3D coordinates are provides as three numbers x, y, z or one array of length 3.

Parameters

Name Type Description
x Number | Array
y Array.<Number>
z Array.<Number>

Returns

Array of length 3 containing the projection on to the board in homogeneous user coordinates.

Type
Array

Details

Source
3d/view3d.js, line 1145

project3DToCube(c3d)

Limit 3D coordinates to the bounding cube.

Parameters

Name Type Description
c3d Array

3D coordinates [x,y,z]

Returns

Array [Array, Boolean] containing [coords, corrected]. coords contains the updated 3D coordinates, correct is true if the coords have been changed.

Details

Source
3d/view3d.js, line 1369

projectScreenToSegment(pScr, end0, end1) → {Array}

Project a point on the screen to the nearest point, in screen distance, on a line segment in 3d space. The inputs and outputs are in homogeneous coordinates.

Used in View3d.project2DTo3DVertical() and Line3d.projectScreenCoords().

Parameters

Name Type Description
pScr Array

The screen coordinates of the point to project.

end0 Array

The world space coordinates of one end of the line segment (array of length 4).

end1 Array

The world space coordinates of the other end of the line segment (array of length 4).

Returns

Homogeneous coordinates of the projection

Type
Array

Details

Source
3d/view3d.js, line 1286

select(str, onlyByIdOrName) → {JXG.GeometryElement3D|JXG.Composition}

Select a single or multiple elements at once.

Example

// select the element with name A
view.select('A');

// select all elements with strokecolor set to 'red' (but not '#ff0000')
view.select({
  strokeColor: 'red'
});

// select all points on or below the x/y plane and make them black.
view.select({
  elType: 'point3d',
  Z: function (v) {
    return v <= 0;
  }
}).setAttribute({color: 'black'});

// select all elements
view.select(function (el) {
  return true;
});

Parameters

Name Type Description
str String | Object | function

The name, id or a reference to a JSXGraph 3D element in the 3D view. An object will be used as a filter to return multiple elements at once filtered by the properties of the object.

onlyByIdOrName Boolean

If true (default:false) elements are only filtered by their id, name or groupId. The advanced filters consisting of objects or functions are ignored.

Returns

Type
JXG.GeometryElement3D | JXG.Composition

Details

Source
3d/view3d.js, line 298

setCurrentView(n) → {Object}

Changes view to the determined view stored in the attribute values.

Parameters

Name Type Description
n Number

Index of view in attribute values.

Returns

Reference to the view.

Type
Object

Details

See
Source
3d/view3d.js, line 1882

setView(az, el, ropt) → {Object}

Sets camera view to the given values. If the optional value r is supplied that value has priority until the next call of view3d.setView or until a call of view3d.freeR(). In particular, the attribute r is ignored until a call of view3d.freeR().

Parameters

Name Type Attributes Description
az Number

Value of azimuth.

el Number

Value of elevation.

r Number <optional>

Value of radius.

Returns

Reference to the view.

Type
Object

Details

See
Source
3d/view3d.js, line 1814

stopAzimuth()

Details

Source
3d/view3d.js, line 1766

(private) updateProjectionTrackball() → {Array}

Determine 4x4 rotation matrix with Bell's virtual trackball.

Returns

4x4 rotation matrix

Type
Array

Details

Source
3d/view3d.js, line 529

worldToFocal(pWorld, homogopt)

Map world coordinates to focal coordinates. These coordinate systems are explained in the JXG.View3D#boxToCam matrix documentation.

Parameters

Name Type Attributes Default Description
pWorld Array

A world space point, in homogeneous coordinates.

homog Boolean <optional>
true

Whether to return homogeneous coordinates. If false, projects down to ordinary coordinates.

Details

Source
3d/view3d.js, line 1120

Inherited

Events

Own

none

Inherited

Parameters

Name Type Description
parents Array

Array consisting of lower left corner [x, y] of the view inside the board, [width, height] of the view and box size [[x1, x2], [y1,y2], [z1,z2]]. If the view's azimuth=0 and elevation=0, the 3D view will cover a rectangle with lower left corner [x,y] and side lengths [w, h] of the board.

Details

Source
3d/view3d.js, line 64

Extends