Here you can find the source of rotatePoint(Point reference, Point toRotate, int degrees)
Parameter | Description |
---|---|
reference | - The point at which the text was drawn |
toRotate | - The approximate center of the drawn text |
degrees | - The degrees by whith the Text/Font is rotated |
public static Point rotatePoint(Point reference, Point toRotate, int degrees)
//package com.java2s; /*//w w w. j ava2 s .c o m * Copyright (c) 2017, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import java.awt.Point; public class Main { /** * Rotates a point with respect to a center point. This is used for calculating * the new center of a character after it has been rotated. * http://www.gamefromscratch.com/post/2012/11/24/GameDev-math-recipes-Rotating-one-point-around-another-point.aspx * * @param reference - The point at which the text was drawn * @param toRotate - The approximate center of the drawn text * @param degrees - The degrees by whith the Text/Font is rotated * @return */ public static Point rotatePoint(Point reference, Point toRotate, int degrees) { double angle = degrees; angle = (angle) * (Math.PI / 180); double rotatedX = Math.cos(angle) * (toRotate.x - reference.x) - Math.sin(angle) * (toRotate.y - reference.y) + reference.x; double rotatedY = Math.sin(angle) * (toRotate.x - reference.x) + Math.cos(angle) * (toRotate.y - reference.y) + reference.y; return new Point((int) rotatedX, (int) rotatedY); } }