buildPlaneVectors function

void buildPlaneVectors (Vector3 planeNormal, Vector3 u, Vector3 v)

Sets u and v to be two vectors orthogonal to each other and planeNormal.

Implementation

void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) {
  if (planeNormal.z.abs() > math.sqrt1_2) {
    // choose u in y-z plane
    final double a =
        planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
    final double k = 1.0 / math.sqrt(a);
    u
      ..x = 0.0
      ..y = -planeNormal.z * k
      ..z = planeNormal.y * k;

    v
      ..x = a * k
      ..y = -planeNormal[0] * (planeNormal[1] * k)
      ..z = planeNormal[0] * (-planeNormal[2] * k);
  } else {
    // choose u in x-y plane
    final double a =
        planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
    final double k = 1.0 / math.sqrt(a);
    u
      ..x = -planeNormal[1] * k
      ..y = planeNormal[0] * k
      ..z = 0.0;

    v
      ..x = -planeNormal[2] * (planeNormal[0] * k)
      ..y = planeNormal[2] * (-planeNormal[1] * k)
      ..z = a * k;
  }
}