Simulator to extract points

Hi Guys

I am working on developing a simulator for laser sensors. I’m having problems using the quaternions.

Explaining the functioning of the project:

  • It has a cube that represents the laser.
  • From this hub rays are fired horizontally and vertically.
  • The rays should be fired in the horizontal angle of 0 to 180 degrees.
  • The vertical beams are fired from angle to angle -45 to 90 (forming 135 degrees)

    I’m having doubts on the use of quaternions, how should I implement this algorithm? Once when I adjust the vertical angle 0, and 0-180 scanning horizontally, it works!

    But when I make the vertical scan, I have problems, since when the angle 0 and angle of 180 scans, should be the same in any variation and the others must vary.

    I hope I was clear.

    Below is the snippet of code generated.

    [java] Geometry[][] mark = new Geometry[181][406];

    //Define a cor do raio laser

    Material mark_mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

    Material mark_mat_green = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

    mark_mat.setColor(“m_Color”, ColorRGBA.Red);

    mark_mat_green.setColor(“m_Color”, ColorRGBA.Green);

    double tamanho_cubo=Math.cbrt((double)cube.getModelBound().getVolume());

    Vector3f origem_raio=new Vector3f((float)((tamanho_cubo/2)+0.05),0,0);

    raio.setOrigin(player.getLocalTranslation().add(origem_raio));

    // laço para realizar as leituras verticais

    for(int k = 0; k <= 180; k+=5){

    float angulo_radiano_k = k * FastMath.DEG_TO_RAD;

    //laço para realizar as 180 leituras horizontais

    for (int j = 0; j < 90; j+=5) {

    float angulo_radiano_j = j * FastMath.DEG_TO_RAD;

    Quaternion r = player.getLocalRotation().fromAngles(angulo_radiano_j, angulo_radiano_k,0);

    raio.setDirection(r.getRotationColumn(2));

    mark[k][j] = new Geometry("mark " + j);

    CollisionResults results = new CollisionResults();

    levelNode.collideWith(raio, results);

    if (results.size() > 0) {

    CollisionResult closest = results.getClosestCollision();

    if(results.getClosestCollision().getDistance()<10){

    Line line = new Line(origem_raio,results.getClosestCollision().getContactPoint().subtract(player.getLocalTranslation()));

    line.setLineWidth(2f);

    mark[k][j].setMaterial(mark_mat);

    mark[k][j].setMesh(line);

    }

    else

    {

    Line line = new Line(origem_raio,raio.getDirection().mult(10));

    line.setLineWidth(2f);

    mark[k][j].setMaterial(mark_mat_green);

    mark[k][j].setMesh(line);

    }

    }

    } // fim do laço horizontal

    //desenha as linhas armazenadas

    } // fim do laço vertical

    for (int k = 0; k <= 180; k+=5) {

    for (int j = 0; j < 90; j+=5) {

    player.attachChild(mark[k][j]);

    }

    }

    [/java]



    grateful for the attention

anybody can help me?

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

Hi,

I read this link, change my code, but don´t work corretly, down follow my code:

[java]public void actionPerformed(ActionEvent e) {

Geometry[][] mark = new Geometry[181][406];

//Define a cor do raio laser

Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

Material mark_mat_green = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

mark_mat.setColor("m_Color", ColorRGBA.Red);

mark_mat_green.setColor("m_Color", ColorRGBA.Green);

//raio.setDirection(r.getRotationColumn(2));

double tamanho_cubo=Math.cbrt((double)cube.getModelBound().getVolume());

Vector3f origem_raio=new Vector3f((float)((tamanho_cubo/2)+0.05),0,0);

raio.setOrigin(player.getLocalTranslation().add(origem_raio));

//(yaw - vertical (varredura horizontal -> eixo y,

//roll - proprio eixo fica 0 -> eixo x ,

//pitch - (varredura verticual) -> z

Vector3f posicao = new Vector3f();

posicao.setX(0);

posicao.setY(1);

posicao.setZ(-1);

//posicao = player.getLocalTranslation();

// laço para realizar as leituras verticais

for(int k = 0; k <= 5; k=k+5){

//int k=0;

Quaternion qz = new Quaternion(player.getLocalRotation());

float angulo_radiano_k = k * FastMath.DEG_TO_RAD;

//Vector3f axis_k = new Vector3f(0,0,1);

if(k<91)

qz.fromAngleAxis(angulo_radiano_k, Vector3f.UNIT_Z);

else

qz.fromAngleAxis(-angulo_radiano_k, Vector3f.UNIT_Z);

//laço para realizar as 180 leituras horizontais

for (int j = 1; j <= 180; j=j+5) {

//converte angulo pra radiano

float angulo_radiano_j = j * FastMath.DEG_TO_RAD;

Quaternion qy = new Quaternion(player.getLocalRotation());

if(j<91)

qy.fromAngleAxis(angulo_radiano_j, Vector3f.UNIT_Y);

else

qy.fromAngleAxis(-angulo_radiano_j, Vector3f.UNIT_Y);

Quaternion qr = qz.mult(qy);

Vector3f direcao_raio = qr.multLocal(posicao);

System.out.println("Direção do raio z=" +k+" y ="+j + direcao_raio);

//pegar os tres valores, jogar no vetor e aplicar no set diretion.

raio.setDirection(direcao_raio);

mark[k][j] = new Geometry("mark " + j);

CollisionResults results = new CollisionResults();

levelNode.collideWith(raio, results);

//System.out.println("Distancia: "+results.getCollision(0).getDistance());

if (results.size() > 0) {

CollisionResult closest = results.getClosestCollision();

if(results.getClosestCollision().getDistance()<10){

Line line = new Line(origem_raio,results.getClosestCollision().getContactPoint());

line.setLineWidth(2f);

mark[k][j].setMaterial(mark_mat);

mark[k][j].setMesh(line);



}

else

{

//Vector3f pontofinal=new Vector3f((float)(5*Math.sin(angulo_radiano_k)Math.cos(angulo_radiano_j)),(float)(5Math.sin(angulo_radiano_j)Math.sin(angulo_radiano_k)),(float)(5Math.cos(angulo_radiano_j)));

Line line = new Line(origem_raio,raio.getDirection().mult(10));

line.setLineWidth(2f);

mark[k][j].setMaterial(mark_mat_green);

mark[k][j].setMesh(line);



}

}

} // fim do laço horizontal

//desenha as linhas armazenadas

} // fim do laço vertical

for (int k = 0; k <= 5; k=k+5) {

for (int j =1; j <= 180; j=j+5) {

player.attachChild(mark[k][j]);

}

}[/java]

This code do ray´s shot forward upward, that rays do not colision, and the rays that have colision ray´s shot reward upward.

Don´t forget that my player is a cube.

Somebody can help me?

thanks again, and thanks for normen