Creating a cylinder from one point to another

I’m looking for a way to create a cylinder that starts at a Vector3f and end’s at another Vector3f. Similar to the Graphics method drawLine(x1, y1, x2, y2) in java that draws a line from one point to another.



I guess you could create a cylinder with the length of v1.distance(v2) and place it between v1 and v2 but then you have to rotate it somehow that I’m not sure how to calculate.

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

1 Like

Great tutorial you got there :slight_smile: I think i know enough to make what I want. I’ll bump this thread if i still can’t solve it myself.

1 Like

This class I made seems to do it, any comments on it? Everything went as expected when I tried it out.



[java]public class LineCylinder extends Geometry{



public LineCylinder(Vector3f start, Vector3f end) {

super("LineCylinder");



Cylinder cyl = new Cylinder(4, 8, .2f, start.distance(end));

this.mesh=cyl;



setLocalTranslation(FastMath.interpolateLinear(.5f, start, end));

lookAt(end, Vector3f.UNIT_Y);

}



}[/java]

1 Like