2017-05-16 6 views
-1

내가 이런 식으로 달성하고자하는 효과를 얻을 수 있습니다 는 어떻게 곡선의 집합을 성장하고 곡선이 다른 사람의 흔적을 발생하면, 그것은 성장의 중지하는

class Particle { 
    PVector position; 
    PVector velocity; 
    PVector acceleration; 
    PVector initialVelocity; 
    ArrayList<PVector> path; 
    boolean life = true; 
    float q; 

    public Particle(PVector position, PVector initialVelocity) { 
    this.position = position; 
    this.acceleration = new PVector(0, 0); 
    this.initialVelocity = initialVelocity; 
    this.velocity = new PVector(0, 0); 
    path = new ArrayList<PVector>(); 
    } 

    public void run() { 
    update(); 
    display(); 
    } 

    private void update() { 
    velocity.add(acceleration); 
    velocity.limit(maxspeed); 
    trail.add(position.copy()); 
    position.add(velocity); 
    occurOtherCurves(); 
    arriveBorders(); 
    path.add(position.copy()); 

    acceleration.mult(0); 
    } 

    private void display() { 
    beginShape(); 
    stroke(0); 
    strokeWeight(1); 
    noFill(); 
    for(PVector v : path) { 
     vertex(v.x, v.y); 
    } 
    } 

    public void followField(Field field) { 
    PVector desired = field.lookup(initialVelocity); 
    desired.mult(maxspeed); 
    PVector steer = PVector.sub(desired, velocity); 
    steer.limit(maxforce); 
    applyForce(steer); 
    } 

    private void applyForce(PVector force) { 
    acceleration.add(force); 
    } 

    public boolean isEndMove(){ 
    return !life; 
    } 

    private void arriveBorders(){ 
    if(position.x <= 0 || position.x >= width || position.y <= 0 || position.y >= height) 
     life = false; 
    } 

    private void occurOtherCurves() { 
    for(PVector p : trail) { 
     if(p.x == position.x && p.y == position.y) life = false;   
    } 
    } 

    public ArrayList<PVector> getPath() { 
    return path; 
    } 
} 
occurOtherCurves() function, ArrayList<PVector> trail은 모든 입자가 통과 한 위치를 기록하는 데 사용되는 전역 변수이지만 작동하지 않았습니다. 도움 주셔서 감사합니다.

답변

0

스택 오버플로는 일반적으로 "어떻게해야합니까?"형식 질문을 위해 설계되지 않았습니다. 더 구체적으로 "나는 X를 시도했는데 Y가 예상 되나 대신 Z가 있습니다"라는 질문을합니다.

하지만 일반적으로 새로운 경로 세그먼트가 기존 경로 세그먼트와 교차하는지 확인하는 것이 좋습니다. 그렇다면 교차점에서 잘라내거나 추가하지 말고 해당 경로에 경로 세그먼트를 추가하는 것을 중지하십시오.

문제를 작은 조각으로 나누고 한 번에 하나씩 취하는 것이 훨씬 더 좋습니다. 그런 다음 문제가 발생하면 MCVE을 특정 기술적 인 질문과 함께 게시 할 수 있습니다. 행운을 빕니다.