Reputation: 431
I'm rotating an Image using RotateTransition and if (x,y) is the position of a point on that image initially and the position will keep on changing as the image rotates. I want to know the poistion of that point at any given time. how to get that new position of the point?
ImageView wheel= new ImageView();
wheel.setImage(image);
rotateTransition = new RotateTransition(Duration.seconds(10), wheel);
rotateTransition.setFromAngle(0);
rotateTransition.setToAngle(360);
rotateTransition.setInterpolator(Interpolator.LINEAR);
rotateTransition.setCycleCount(Timeline.INDEFINITE);
//Current method I'm following doesn't seems to be accurate:
rotateTransition.currentTimeProperty().addListener(
new ChangeListener<Duration>() {public void changed(ObservableValue<? extends Duration> ov, Duration t, Duration t1) {
double degree = ((360 * t.toSeconds()) / 10);
xVal.set(((120) * Math.cos(degree * (Math.PI / 180))) + 162.5);
yVal.set(((120) * Math.sin(degree * (Math.PI / 180)) + 162.5));
}
Upvotes: 3
Views: 314
Reputation: 29520
To get the current angle of the rotation, you should use the rotateProperty of the ImageView
:
wheel.rotateProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldValue,
Number newValue) {
System.err.println("Rotation of " + newValue + " degrees");
}
});
Upvotes: 1