NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 9937|回复: 12

[在线求助] 关于在线视频里的找轨迹连线的问题,求指导~

  [复制链接]
发表于 2012-9-11 09:57:18 | 显示全部楼层 |阅读模式
1.jpg 程序出错运行不了,不知道哪里错了,求版主指导 2.jpg 3.jpg 4.jpg 5.jpg 6.jpg 7.jpg 8.jpg 9.jpg 10.jpg
 楼主| 发表于 2012-9-11 09:59:04 | 显示全部楼层
图片有些多 ,因为我也不知道哪里出错了导致运行不了,所以全都截图上来了,谢谢各位帮助~小妹先行谢过
发表于 2012-9-11 10:35:19 | 显示全部楼层

完全可以把代码贴上来看着方便嘛~~
 楼主| 发表于 2012-9-11 11:15:01 | 显示全部楼层
(1).Line
import toxi.math.conversion.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.geom.mesh2d.*;
import toxi.util.datatypes.*;
import toxi.util.events.*;
import toxi.geom.mesh.subdiv.*;
import toxi.geom.mesh.*;
import toxi.math.waves.*;
import toxi.util.*;
import toxi.math.noise.*;

import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;

import processing.opengl.*;

ArrayList ballCollection=new ArrayList();

Ball basketBall;
PeasyCam cam;
float a=300;

void setup() {
  cam=new PeasyCam(this, 600);
  size(600, 400, OPENGL);
  smooth();
  for (int i=0;i<10;i++) {
    Vec3D loc=new Vec3D(0, 0, -a/2);
    Vec3D vel=new Vec3D(random(-5, 5), random(-5, 5), random(-5, 5));
    basketBall=new Ball(loc, vel);
    ballCollection.add(basketBall);
  }
}

void draw() {
  background(0);
  stroke(255);
  strokeWeight(1);
  noFill();
  box(2*a);
  frameRate(30);

  for (int i=0;i< ballCollection.size();i++) {
    Ball ball =(Ball) ballCollection.get(i);
    ball.run();
  }

  for (int i=0;i< ballCollection.size();i++) {
    Ball ball =(Ball) ballCollection.get(i);
    for (int j=0;j< ball.pointsList.size()-1;j++) {
      Trace agent1=(Trace) ball.pointsList.get(j);
      Trace agent2=(Trace) ball.pointsList.get(j+1);
      
      agent1.run();
      stroke(255, 50);
      strokeWeight(1);
      line(agent1.loc.x, agent1.loc.y, agent1.loc.z, agent2.loc.x, agent2.loc.y, agent2.loc.z);
    }
  }
}


(2).Ball
class Ball {
  Vec3D loc;
  Vec3D vel;
  ArrayList pointsList=new ArrayList();
  
  Vec3D gravity=new Vec3D (0, 0, -0.1);

  Ball(Vec3D _loc, Vec3D _vel) {
    loc = _loc;
    vel = _vel;
  }
  void run() {
    display();
    moveBall();
    boundary();
    gravity();
    createPoints();
  }

  void createPoints(){
    if (vel.magnitude() > 1 &&  loc.z>-290){
    Vec3D agentLoc=new Vec3D();
    agentLoc=this.loc.copy();
    Trace agents = new Trace(agentLoc,this);
    this.pointsList.add(agents);
  }
  }

  void friction() {
    vel.scaleSelf(0.8);
  }
  void gravity() {
    vel.addSelf(gravity);
  }

  void boundary() {
    if (loc.x>=300) {
      loc.x=300;
      vel.x=-vel.x;
      friction();
    }
    if (loc.x<=-300) {
      loc.x=-300;
      vel.x=-vel.x;
      friction();
    }

    if (loc.y>=300) {
      loc.y=300;
      vel.y=-vel.y;
      friction();
    }
    if (loc.y<=-300) {
      loc.y=-300;
      vel.y=-vel.y;
      friction();
    }

    if (loc.z>=300) {
      loc.z=300;
      vel.z=-vel.z;
      friction();
    }
    if (loc.z<=-300) {
      loc.z=-300;
      vel.z=-vel.z;
      friction();
    }
  }

  void display() {
    stroke(255, 0, 0);
    strokeWeight(10);
    point(loc.x, loc.y, loc.z);
  }
  void moveBall() {
    loc.addSelf(vel);
  }
}


(3).Trace
class Trace {
  Vec3D loc;
  Ball parent;
  int id_Ball;
  int id_Trace;
  boolean found = false;


  Trace(Vec3D _loc,Ball _parent) {
    loc= _loc;
    parent =  _parent;
  }
  
  void run() {
    //display();
    connection();
  }
  
  void connection(){
    float minDis=100000;
  if(found == false){  
   
  for(int i=0,i< ballCollection.size();i++){
  Ball otherBall=(Ball) ballCollection.get(i);
  if(otherBall != this.parent){
  for(int j=0,j< otherBall.pointsList.size(),j++){
  Trace otherTrace=(Trace) otherBall.pointsList.get(j);
  float dis =this.loc.distanceTo(otherTrace.loc);
  if(dis < minDis){
  minDis=dis;
  id_Ball=i;
  id_Trace=j;
  }
  }
  }
  }
  found = true;
  }
  
  
  
  Ball minBall=(Ball) ballCollection.get(id_Ball);
  Trace minTrace=(Trace) minBall.pointsList.get(id_Trace);
  line(this.loc.x,this.loc.y,this.loc.z,minTrace.loc.x,minTrace.loc.y,minTrace.loc.z);
  }
  
  void  display() {
    stroke(255);
    strokeWeight(2);
    point (loc.x, loc.y, loc.z);
  }
}

 楼主| 发表于 2012-9-11 11:15:49 | 显示全部楼层
发表于 2012-9-11 11:40:35 | 显示全部楼层
eaTion 发表于 2012-9-11 11:15
嘿嘿,谢谢提醒 一时没想起来,现在贴上了  求帮助

我是个小鬼~~帮不了你什么~~~如果你特别急的话~~建议你去群里面吼一声~~~或者给panhao、nixy、line这样的大神们发个私信~~~据我所知,大神们一般很少有时间看帖子~~~
 楼主| 发表于 2012-9-11 12:43:43 | 显示全部楼层
活建鬼 发表于 2012-9-11 11:40
我是个小鬼~~帮不了你什么~~~如果你特别急的话~~建议你去群里面吼一声~~~或者给panhao、nixy、line这样的 ...

谢谢你 活见鬼 哈哈
 楼主| 发表于 2012-9-11 13:32:39 | 显示全部楼层
额  我知道哪里错了   不细心真的害死人啊  在for()里的“;”写成了“,”   希望以后各位朋友也注意一下
发表于 2012-9-13 00:36:35 | 显示全部楼层
没看出啥问题啊?

QQ截图20120913003358.jpg

除了几个分号被你写成逗号的小错误(你图上就提示了colon啊),没有逻辑错误啊?
反驳下 活见鬼 的话,我们还是常常在线的。
发表于 2012-9-13 00:37:39 | 显示全部楼层
eaTion 发表于 2012-9-11 13:32
额  我知道哪里错了   不细心真的害死人啊  在for()里的“;”写成了“,”   希望以后各位朋友也注意一下 ...

建议你用eclipse 这种小错误自动改过来
 楼主| 发表于 2012-9-13 23:36:24 | 显示全部楼层
panhao1 发表于 2012-9-13 00:37
建议你用eclipse 这种小错误自动改过来

谢谢版主  已经下载了eclipse 正在学习中 呵呵
发表于 2012-9-19 19:35:01 | 显示全部楼层
eaTion 发表于 2012-9-13 23:36
谢谢版主  已经下载了eclipse 正在学习中 呵呵

今天也刚刚 下了eclipse     多交流
发表于 2012-10-25 15:45:53 | 显示全部楼层
哦,还真是很强大呀,要好好学!

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-4-19 01:23 , Processed in 0.070157 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表