2017-02-01 1 views
1

가공시 3 축 좌표계를 그리는 프로그램을 만들고 점의 좌표 A (x, y, z)를 입력 받아 3 축 좌표로 표시하고 싶습니다. 시스템, 여기 누구든지 내가 시작할 수있는 코드를 제공 할 수 있습니까?3 축 가공시 좌표계 3.2.4

답변

1

line() 함수를 사용하고 두 쌍의 x, y, z 좌표 (3D에서 선의 "시작점"과 "끝점")를 전달하면 쉽게 축을 그릴 수 있습니다.

3 선 그리기와 (예를 들어 X가 Y, R, G 등의 Z는, B)을해야 색상으로 각 축 색칠 :

void drawAxes(float size){ 
    //X - red 
    stroke(192,0,0); 
    line(0,0,0,size,0,0); 
    //Y - green 
    stroke(0,192,0); 
    line(0,0,0,0,size,0); 
    //Z - blue 
    stroke(0,0,192); 
    line(0,0,0,0,0,size); 
} 

당신이 좌표계를 여러 사용할 계획이라면, 그것은 가치가 독서의 2D transformations tutorial. 당신은 노호 p5.js preview를 실행할 수 있습니다

PVector a = new PVector(100,50,20); 

void setup(){ 
    size(400,400,P3D); 
    strokeWeight(3); 
} 
void draw(){ 
    background(255); 
    //draw original coordinate system 
    drawAxes(100); 
    //draw from centre and rotate with mouse 
    translate(width * 0.5, height * 0.5, 0); 
    rotateX(map(mouseY,0,height,-PI,PI)); 
    rotateY(map(mouseX,0,width,PI,-PI)); 

    //draw centred coordinate system 
    drawAxes(100); 

    //isolate coordinate system for A point 
    pushMatrix(); 
    translate(a.x,a.y,a.z); 
    //draw translated A point 
    drawAxes(50); 
    popMatrix(); 
} 
void drawAxes(float size){ 
    //X - red 
    stroke(192,0,0); 
    line(0,0,0,size,0,0); 
    //Y - green 
    stroke(0,192,0); 
    line(0,0,0,0,size,0); 
    //Z - blue 
    stroke(0,0,192); 
    line(0,0,0,0,0,size); 
} 

: 같은 개념을 분리하고 pushMatrix()/popMatrix() 호출을 사용하여 좌표계를 중첩의 측면에서뿐만 아니라 3D로 적용

<iframe width="400" height="400" src="https://alpha.editor.p5js.org/embed/HkQoQTAvl" style="border:none;"></iframe>