Problems with cylinder and spheres

hi,



i have the following problem. i want to create a graph g=(v,e) with jmonkey. so spheres are vertices and cylinder or tubes are edges. my program generates five vertices on random positions and now i want to add edges between them. i tried to create a cylinder and moved them to the point m = (m1 + m2) / 2, where m1 and m2 are the center points of vertice one and vertice two. now i rotated the cylinder using:



cylinder.setLocalTranslation(m);



Matrix3f rot = new Matrix3f();

rot.loadIdentity();

rot.fromStartEndVectors(m1, m2);



cylinder.setLocalRotation(rot);



but the rotation does not work!!!



What can i do to solve this problem?



Is there a better way to create a graph g=(v,e) ?



Can someone post sample source code?

In your case I would skip the cylinders and use the "Line" geometry instead as in the following link:



http://www.jmonkeyengine.com/doc/com/jme/scene/Line.html



if you use the following constructor:



Line(java.lang.String name, Vector3f[] vertex, Vector3f[] normal, ColorRGBA[] color, Vector2f[] texture)



you can easily create lines, the only thing you need is the two positions the line consists of. That is, the vertex array consists of the two Vector3f points you want the line to go between. Actually I think you can draw your entire graph with this, just put the vertexes in the correct order. I havn't tested this though, but I am certain you can easily create lines with it anyway.



Of course you should add color to the line, which is done by adding which color each vertice should be. So if you want a red line, then color should look like this:



ColorRGBA[] color = {new ColorRGBA(1, 0, 0, 0), new ColorRGBA(1, 0, 0, 0)};



You will probably not need the normals, so just set them to null, and if you don't want textures, set this to null also.



I can also add that you can set the line width, which makes them look as you used cylinders.



This is probably WAY easier than using Cylinders.



good luck!

thx, i tried them but lines don't looks like a 3d cylinder or anything. they are simple 2d objects and have no perspective, so the whole edges are flat. is there no way to design them all as 3d objects?

okay, I actually didn't notice that when I used them, since I used them in such a small scale, so you couldn't see that they where drawn in 2D.



In that case I don't think it is possible to get them in 3D, you will probably have to try with the cylinders again…



But if I look at your original code I'm not sure that the function "fromstarttoend" will do what you want (I'm not sure though). I interpret the documentation as it takes in two directional vectors, but your vectors aren't directional vectors, they are just points. Therefore your rotation isn't what you expect.



I would recommend trying with ordinary algebra.



http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm