Skip to content

add(buffer): Normalize #29

Description

@gsimone
normalize(buffer, size)

const myRandoms = pipe(
   new Float32Array(10_000 * 3),
   b => inSphere(b),
   b => normalize(b, 3),
  b => map(b, 
)

impl:

const normalize = (buffer: TypedArray, stride: number) => {
  for (let i = 0; i < buffer.length; i += stride) {
    const x = buffer[i + 0];
    const y = buffer[i + 1];
    const z = buffer[i + 2];
    const l = Math.sqrt(x * x + y * y + z * z);
    buffer[i + 0] = x / l;
    buffer[i + 1] = y / l;
    buffer[i + 2] = z / l;
  }
  return buffer;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions