Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(buffer): Normalize #29

Open
gsimone opened this issue Dec 8, 2022 · 0 comments
Open

add(buffer): Normalize #29

gsimone opened this issue Dec 8, 2022 · 0 comments

Comments

@gsimone
Copy link
Member

gsimone commented Dec 8, 2022

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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant