Path.arc()
方法可以创建一个圆弧路径段。
path.arc(centerX, centerY, radius, startAngle, endAngle, counterclockwise);
centerX
:圆心的 x 坐标。centerY
:圆心的 y 坐标。radius
:圆的半径。startAngle
:起始角度,以弧度表示。从 x 轴正方向逆时针方向为正方向。endAngle
:结束角度,以弧度表示。counterclockwise
:是否按逆时针方向绘制圆弧。默认为 false
,即按顺时针方向绘制圆弧。无返回值。
// 创建一个画布
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// 创建一个场景
const scene = new THREE.Scene();
// 创建一个线条材质
const material = new THREE.LineBasicMaterial({ color: 0x00ff00 });
// 创建一个路径对象
const path = new THREE.Path();
// 添加一段圆弧路径
path.arc(0, 0, 50, 0, Math.PI, true);
// 使用路径创建线条几何体
const geometry = path.createPointsGeometry(50);
// 创建线条对象
const line = new THREE.Line(geometry, material);
// 将线条对象添加到场景中
scene.add(line);
// 创建一个相机
const camera = new THREE.PerspectiveCamera(75, canvas.width / canvas.height, 0.1, 1000);
camera.position.z = 100;
// 创建一个渲染器
const renderer = new THREE.WebGLRenderer({ canvas });
// 渲染场景
renderer.render(scene, camera);