#include <math.h>

typedef struct {
  フロートX;
  フロートy;
  フロートZ;
} point3;

typedef struct {
  Point3 x;
  ポイント3 Y;
  Point3 Z;
  Point3翻訳;
} matrix3;

matrix3 matrixfromnomnomal（point3垂直）{
  Matrix3の結果;
  float length = sqrtf（normal.x * normal.x + normor.y * normor.y + normor.z * normal.z）;
  result.z =（point3）{normal.x / leangth、normal.y / leangh、normal.z / leength};
  if（fabsf（result.z.x）<fabsf（result.z.y））{
    float a = 1.0f / sqrtf（result.z.y * result.z.z.y + result.z.z * result.z.z）;
    result.x =（point3）{result.z.z * a、0.0f、-result.z.y * a};
  } それ以外 {
    float a = 1.0f / sqrtf（result.z.x * result.z.z.x + result.z.z * result.z.z）;
    result.x =（point3）{0.0f、result.z.z * a、-result.z.x * a};
  }
  result.y =（point3）{result.z.y * result.x.z -result.z.z * result.x.y、
                     result.z.z * result.x.x -result.z.x * result.x.z、
                     result.z.x * result.x.y -result.z.y * result.x.x};
  result.translation =（point3）{0.0f、0.0f、0.0f};
  返品結果;
}
#include <math.h>

typedef struct {
  float x;
  float y;
  float z;
} point3;

typedef struct {
  point3 x;
  point3 y;
  point3 z;
  point3 translation;
} matrix3;

matrix3 MatrixFromNormal(point3 normal) {
  matrix3 result;
  float length = sqrtf(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z);
  result.z = (point3){normal.x / length, normal.y / length, normal.z / length};
  if (fabsf(result.z.x) < fabsf(result.z.y)) {
    float a = 1.0f / sqrtf(result.z.y * result.z.y + result.z.z * result.z.z);
    result.x = (point3){result.z.z * a, 0.0f, -result.z.y * a};
  } else {
    float a = 1.0f / sqrtf(result.z.x * result.z.x + result.z.z * result.z.z);
    result.x = (point3){0.0f, result.z.z * a, -result.z.x * a};
  }
  result.y = (point3){result.z.y * result.x.z - result.z.z * result.x.y,
                     result.z.z * result.x.x - result.z.x * result.x.z,
                     result.z.x * result.x.y - result.z.y * result.x.x};
  result.translation = (point3){0.0f, 0.0f, 0.0f};
  return result;
}