本文整理汇总了Java中javafx.scene.shape.Cylinder.setTranslateZ方法的典型用法代码示例。如果您正苦于以下问题:Java Cylinder.setTranslateZ方法的具体用法?Java Cylinder.setTranslateZ怎么用?Java Cylinder.setTranslateZ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.shape.Cylinder
的用法示例。
在下文中一共展示了Cylinder.setTranslateZ方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCylinderConnecting
import javafx.scene.shape.Cylinder; //导入方法依赖的package包/类
private Cylinder createCylinderConnecting(Vector3D source, Vector3D target) {
Vector3D delta = target.subtract(source);
double distance = source.distanceTo(target);
Cylinder bond = new Cylinder(0.4, distance, 10);
Vector3D newLocation = delta.divide(2).add(source);
bond.setTranslateX(newLocation.getX());
bond.setTranslateY(newLocation.getY());
bond.setTranslateZ(newLocation.getZ());
// phi
bond.getTransforms().add(new Rotate(90 + Math.toDegrees(Math.atan2(delta.getY(), delta.getX())), Rotate.Z_AXIS));
// theta
bond.getTransforms().add(new Rotate(90 + Math.toDegrees(Math.acos(delta.getZ() / distance)), Rotate.X_AXIS));
return bond;
}
示例2: createShape
import javafx.scene.shape.Cylinder; //导入方法依赖的package包/类
/**
* Creates a cylinder between the start and end points of the edge.
*
* @return A JavaFX Cylinder representing the given LinearEdgeComponent
*/
private Cylinder createShape(Edge edgeComponent) {
// If the edge does not have two vertices, a new shape cannot be created
if (edgeComponent.getEntitiesFromCategory(MeshCategory.VERTICES)
.size() != 2) {
return null;
}
// Get the scale the vertices are being drawn at
int scale = ((FXVertexController) edgeComponent
.getEntitiesFromCategory(MeshCategory.VERTICES).get(0))
.getApplicationScale();
// Get the edge's endpoints
double[] start = edgeComponent.getStartLocation();
double[] end = edgeComponent.getEndLocation();
for (int i = 0; i < 3; i++) {
start[i] = start[i] * scale;
end[i] = end[i] * scale;
}
// Create a cylinder situated at the edge's midpoint with the edge's
// length.
Cylinder edge = new Cylinder(.6,
Math.sqrt((Math.pow(start[0] - end[0], 2))
+ (Math.pow(start[1] - end[1], 2))
+ (Math.pow(start[2] - end[2], 2))));
edge.setTranslateX((start[0] + end[0]) / 2);
edge.setTranslateY((start[1] + end[1]) / 2);
edge.setTranslateZ((start[2] + end[2]) / 2);
// Get the angle between the two points
Point3D start3D = new Point3D(start[0], start[1], start[2]);
Point3D end3D = new Point3D(end[0], end[1], end[2]);
Point3D angle = end3D.subtract(start3D);
// Get the axis of rotation for the cylinder
Point3D axis = angle.crossProduct(0f, 1f, 0f);
// Calculate the number of degrees to rotate about the axis.
double rotationAmount = Math
.acos(angle.normalize().dotProduct(0, 1, 0));
// Apply the rotation to the cylinder
Rotate rotation = new Rotate(-Math.toDegrees(rotationAmount), axis);
edge.getTransforms().addAll(rotation);
return edge;
}