我從另一個程序試圖輸入一些已知的ACR值,並複製它們在three.js所如何繪製2D弧
現在我用下面的代碼我在此網站上發現。它畫出的弧線很好,但它可能不是最好的選擇。
function DRAWarc(){
// smooth my curve over this many points
var numPoints = 100;
spline = new THREE.SplineCurve3([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 200, 0),
new THREE.Vector3(150, 150, 0)
]);
var material = new THREE.LineBasicMaterial({
color: 0xff00f0,
});
var geometry = new THREE.Geometry();
var splinePoints = spline.getPoints(numPoints);
for(var i = 0; i < splinePoints.length; i++){
geometry.vertices.push(splinePoints[i]);
}
var line = new THREE.Line(geometry, material);
scene.add(line);
}
以下是已知的變量。
中心點(X,Y)(如果都得一個完整的圓圈,圓圈的中心)
半徑(如果它是一個圓)
起始角(我還不能肯定,但我認爲這是度數,如果它是一個圓,逆時針旋轉,0表示圓的右側)
結束角(見上)
更多代碼!
///////////
// SCENE //
///////////
scene = new THREE.Scene();
////////////
// CAMERA //
////////////
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
viewsize = 900;
camera = new THREE.OrthographicCamera(
SCREEN_WIDTH/- 2, SCREEN_WIDTH/2,
SCREEN_HEIGHT/2, SCREEN_HEIGHT/- 2,
1, 1e6);
camera.position.z = 2000;
scene.add(camera);
camera.lookAt(new THREE.Vector3(2100, 3600, 0));
//////////////
// RENDERER //
//////////////
// create and start the renderer
if (Detector.webgl){
renderer = new THREE.WebGLRenderer();
//alert('no problem.');
}else{
renderer = new THREE.CanvasRenderer();
alert('problem.');
}
renderer.setClearColor("white", 1);
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.body;
container.appendChild(renderer.domElement);
////////////
// EVENTS //
////////////
// automatically resize renderer
THREEx.WindowResize(renderer, camera);
// toggle full-screen on given key press
THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) });
///////////
// STATS //
///////////
// displays current and past frames per second attained by scene
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild(stats.domElement);
///////////
// LIGHT //
///////////
// create a light
var light = new THREE.PointLight(0xffffff);
light.position.set(0,250,0);
scene.add(light);
var ambientLight = new THREE.AmbientLight(0x111111);
// scene.add(ambientLight);
//////////////
// GEOMETRY //
//////////////
// most objects displayed are a "mesh":
// a collection of points ("geometry") and
// a set of surface parameters ("material")
doWork();
}
function animate()
{
requestAnimationFrame(animate);
render();
update();
}
function update()
{
// delta = change in time since last call (in seconds)
var delta = clock.getDelta();
// functionality provided by THREEx.KeyboardState.js
if (keyboard.pressed("1"))
document.getElementById('message').innerHTML = ' Have a nice day! - 1';
if (keyboard.pressed("2"))
document.getElementById('message').innerHTML = ' Have a nice day! - 2 ';
//controls.update();
stats.update();
}
function render()
{
renderer.render(scene, camera);
}`
我們可以看一下你的代碼的其餘部分,好嗎?也許作爲一個jsFiddle? – jameslafferty
哥們我有28000行代碼:P你想看什麼?思考過後,這基本上是一個數學問題......我需要一種算法將數據轉換爲三點,然後上面的代碼才能滿足我的需求。順便說一句,代碼是好的只是想顯示我正在嘗試 – contehhh
28千行可能是矯枉過正。我只是在尋找一個能夠充分說明你想要做什麼的例子。例如,我不知道'''scene''是從哪裏來的,或者是否讓''''''''''''''''''''''''全局有什麼意義。根據你在這裏得到的結果,很難完全回答這個問題。 – jameslafferty