Point3 Values

The Point3 class defines the characteristics of points in 3D space. These values are also known as 3D vectors, and contain 3 component floating point numbers. All the coordinates passed to and from 3ds max are in these values. See also 2D and 3D Point Literals.

Literals

[ <expr>, <expr>, <expr> ]

Examples:

[x, y, z]

[10, 10, 10]

[sin x, cos y, tan z]

x_axis                   -- equivalent to [1,0,0]

y_axis                   -- equivalent to [0,1,0]

z_axis                   -- equivalent to [0,0,1]

Constructors

point3 <x> <y> <z>

<color> as point3

Properties

<point3>.x       : Float -- the x coordinate

<point3>.y       : Float -- the y coordinate

<point3>.z       : Float -- the z coordinate

Operators

<point3> == <point3>

<point3> != <point3>

<point3> + <point3_or_number>

<point3> - <point3_or_number>

<point3> * <point3_or_number>

<point3> / <point3_or_number>

Standard vector arithmetic. If the second operand is a number, the operation is performed on each component of the value.

<point3> * <matrix3>

Transforms point3 into the coordinate system specified by matrix3.

<point3> * <quat>

rotates point3

- <point3>

unary minus

Methods

copy <point3>

Creates a new copy of the point3 value. For example:

newPos = copy oldPos

The new value contains a copy of the input point3 value, and is independent of the input point3 value.

length <point3>

Returns the length of the vector.

dot <point3> <point3>

Returns the vector dot product.

cross <point3> <point3>

Returns the vector cross product.

normalize <point3>

Returns the point3 value normalized such that the vector length equals 1.

distance <point3> <point3>

Returns the distance between the points - length of (point 2 û point 1).

random <point3> <point3>

Generates a pseudo-random point between the given points.

arbAxis <point3>

Returns a Matrix3 value representing an arbitrary axis system using point3 as the "up" direction.

matrixFromNormal <point3>

Returns a Matrix3 value with the normal specified by the given point as the Z axis. The translation portion of the Matrix3 value will be [0,0,0]. The components of the scale portion are the inverse of the values required to normalize the point3 value. For example,

MatrixFromNormal [0,0,1]

MatrixFromNormal [0,1,1]

will return

(matrix3 [1,0,0], [0,1,0], [0,0,1], [0,0,0])

(matrix3 [0,-0.707107,0.707107] [1.41421,0,0] [0,1,1] [0,0,0])

-- 3D Noise Functions

noise3 <point3>

A floating point noise function over 3D space, implemented by a pseudo-random tricubic spline. The return value is in the range -1.0 to +1.0. Given the same point3 value, the noise3() function always returns the same value.

noise4 <point3> <phase_float>

The same function as noise3 in which the phase can be varied using the second parameter. The return value is in the range -1.0 to +1.0.

turbulence <point3> <frequency_float>

This is a simple fractal-loop turbulence built on top of the noise3 function. The second parameter controls the frequency of the turbulence. The return value is in the range 0.0 to +1.0.

fractalNoise <point3> <H_float> <lacunarity_float> <octaves_float>

This is a fractal function of 3D space implemented using fractional Brownian motion. The function is homogeneous and isotropic. It returns a float.

The parameters are as follows:

point3 - The point in space at which the noise is computed.

H_float - The fractal increment parameter in the range [0,1]. When H_float is 1 the function is relatively smooth; as H_float goes to 0, the function approaches white noise.

lacunarity_float - The gap between successive frequencies, best set at 2.0.

octaves_float - The number of frequencies in the function.

All the noise functions are based on code and algorithms in the book "Texturing and Modeling: A Procedural Approach", Musgrave, Peachey, Perlin and Worley. Academic Press, ISBN: 0-12-228760-6.

Examples

The following script shows the use of various literals, constructors, properties, operators, and methods of the Point3 class.

The following script was written as a test bed for the noise functions. This script displays a 2 dimensional slice of the noise function output as a bitmap. By changing the noise parameters in lines 4 through 10, and specifying which noise function to evaluate in line 12, you can see the effects of changes in the parameters and using different noise functions.

Script

-- noise functions test bed

b_width=320        -- specify size of bitmap

b_height=320

size=10.           -- total distance covered by each row and column

z=0.               -- z coordinate of 2D slice

phase=0.5          -- noise4 parameter

frequency=10.      -- turbulence parameter

fract_interval=.5  -- fractalNoise parameters

lacunarity=2.

octaves=5

--

whichfunc=1        -- 1 = noise3; 2 = noise4; 3 = turbulence; 4 = fractalNoise

--

b=bitmap b_width b_height     -- create the bitmap

for h=0 to (b_height-1) do    -- step through each row of the bitmap

(

h_norm=(h as float/(b_height-1))*size -- calculate y coordinate

row = for w=0 to (b_width-1) collect -- collect row of pixel colors

(

w_norm=(w as float/(b_width-1))*size -- calculate x coordinate

noise_val = case whichfunc of -- store result of selected function

(

1: noise3 [w_norm, h_norm , z]

2: noise4 [w_norm, h_norm , z] phase

3: turbulence [w_norm, h_norm , z] frequency

4: fractalNoise [w_norm, h_norm , z] fract_interval lacunarity octaves

)

noise_val = 0.5*(1.+noise_val) -- convert output range to 0. to 1.

white*noise_val -- and multiply by color white

)

setpixels b [0,h] row -- store row of pixels in bitmap

)

display b                            -- display bitmap in VFB

Output

The following figures show the bitmap generated by the above script for each noise function type.

noise3

noise4

turbulence

fractalNoise