BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

MathUtils.euclideanModulo()

The MathUtils.euclideanModulo() method is a function that returns the euclidean modulo of a given dividend and divisor. The euclidean modulo is a value between 0 (inclusive) and the absolute value of the divisor (exclusive).

Syntax

MathUtils.euclideanModulo(dividend, divisor)

Parameters

dividend - A number representing the dividend in the equation.

divisor - A number representing the divisor in the equation.

Return value

The MathUtils.euclideanModulo() method returns a number representing the euclidean modulo of the dividend and divisor.

Examples

MathUtils.euclideanModulo(7, 3); //returns 1

MathUtils.euclideanModulo(-7, 3); //returns 2

MathUtils.euclideanModulo(7, -3); //returns 1

MathUtils.euclideanModulo(-7, -3); //returns 2

Remarks

If either dividend or divisor is not a number, or if divisor is 0, NaN is returned.

MathUtils.euclideanModulo() works by first calculating the regular modulo using the % operator, and then adjusting the value to fall within the euclidean range. This is done by adding the absolute value of the divisor to the value until it is greater than or equal to 0 and less than the absolute value of the divisor.

This method can be useful in many mathematical algorithms, such as calculating the index of an array in a circular manner, or determining the position of an element in an evenly spaced grid.