rotation3D

euler angles

by j91157j91157

HTML

<div id="info">Orientation 3D
  <br>spiral curve</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/84/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://jyunming-chen.github.io/tutsplus/js/KeyboardState.js"></script>

CSS

#info {
  position: absolute;
  top: 0px;
  width: 100%;
  padding: 10px;
  text-align: center;
  color: #ffff00
}

body {
  overflow: hidden;
}

JavaScript

var camera, scene, renderer, light, controls;
var plane, theta = 0, R = 2, pitch = 10;

init();
animate();



// make a right handed spiral
// until y > ymax
// 每週 12 點, pitch 為每週y前進距離
// (每點y前進 pitch/12)
// 總共 floor(ymax/ (pitch/12)) 點

function makeSpiral(r, pitch, ymax) {
  let numberPoints = Math.floor(ymax / pitch * 12)
  var material = new THREE.LineBasicMaterial({
    color: 0xffff00
  });
  let geometry = new THREE.Geometry();
  let theta = 0;
  for (let i = 0; i < numberPoints; i++) {
    theta = i * Math.PI * 2 / 12;
    geometry.vertices.push(new THREE.Vector3(r * Math.cos(theta), i* pitch / 12, -r * Math.sin(theta)));
  }
  var line = new THREE.Line(geometry, material);
  return line;
}

function buildPlane() {
	var plane = new THREE.Object3D();
  
	var geometry = new THREE.Geometry();
  geometry.vertices.push(new THREE.Vector3(15, 0, 0));
  geometry.vertices.push(new THREE.Vector3(0, 5, 0));
  geometry.vertices.push(new THREE.Vector3(0, 0, 5));
  geometry.vertices.push(new THREE.Vector3(0, 0, -5));
  var face;
  face = new THREE.Face3(0, 1, 2);
  geometry.faces.push(face);
  face = new THREE.Face3(1, 3, 2);
  geometry.faces.push(face);
  face = new THREE.Face3(3, 1, 0);
  geometry.faces.push(face);
  face = new THREE.Face3(2, 3, 0);
  geometry.faces.push(face);

  geometry.computeBoundingSphere();
  geometry.computeFaceNormals();
  geometry.computeVertexNormals();

  mesh = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial());
  plane.add(mesh);
  
  var axis0 = new THREE.Mesh (new THREE.CylinderGeometry (1,1,30), new THREE.MeshBasicMaterial({color:0xff0000}));
  var axis1 = new THREE.Mesh (new THREE.CylinderGeometry (1,1,30), new THREE.MeshBasicMaterial({color:0x00ff00}))
  var axis2 = new THREE.Mesh (new THREE.CylinderGeometry (1,1,30), new THREE.MeshBasicMaterial({color:0x0000ff}));

	plane.add (axis0);
  plane.add (axis1);
  plane.add (axis2);
  axis0.position.set (15,0,0);
  axis0.rotation.z = - Math.PI/2;
  axis1.position.set (0,15,0);
 ...