Java에서 X축을 중심으로 2D 모양을 회전하고 크기를 조정하는 방법은 무엇입니까?
크기 조정을 사용하여 X축을 중심으로 도형을 수직으로 회전
문제:
귀하 x 및 y축이 있는 2D 그래프가 있고 크기 조정 기능을 통합하면서 축을 중심으로 모양을 회전하려고 합니다.
해결책:
이를 달성하려면 회전 및 크기 조정과 같은 변환을 사용하여 모양의 점을 조작할 수 있습니다. 다음은 먼저 고정된 각도로 모양을 회전한 다음 다양한 배율로 크기를 조정하는 예입니다.
<code class="java">import java.awt.*; import java.awt.event.*; import java.awt.geom.AffineTransform; import javax.swing.*; public class ShapeRotationScaling extends JPanel implements ActionListener { private static final int ANGLE_INCREMENT = 1; // in degrees private static final double SCALE_INCREMENT = 0.1; private int[] shapeXPoints = {200, 200, 240, 240, 220, 220, 200}; private int[] shapeYPoints = {200, 260, 260, 240, 240, 200, 200}; private AffineTransform transform = new AffineTransform(); private double rotationAngle = 0; private double scaleFactor = 1; private Timer timer = new Timer(100, this); public ShapeRotationScaling() { this.setPreferredSize(new Dimension(700, 700)); this.setBackground(Color.white); timer.start(); } @Override public void actionPerformed(ActionEvent event) { // Rotate the shape around the x-axis transform.rotate(Math.toRadians(rotationAngle), this.getWidth() / 2, 0); // Scale the shape transform.scale(scaleFactor, scaleFactor); // Increment the rotation angle and scale factor rotationAngle += ANGLE_INCREMENT; scaleFactor += SCALE_INCREMENT; repaint(); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Draw the x and y axes g2d.drawLine(this.getWidth() / 2, 0, this.getWidth() / 2, this.getHeight()); g2d.drawLine(0, this.getHeight() / 2, this.getWidth(), this.getHeight() / 2); // Apply the transformation to the shape and draw it Shape rotatedAndScaledShape = transform.createTransformedShape(new Polygon(shapeXPoints, shapeYPoints, shapeXPoints.length)); g2d.draw(rotatedAndScaledShape); } public static void main(String[] args) { JFrame frame = new JFrame("Shape Rotation and Scaling"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ShapeRotationScaling sr = new ShapeRotationScaling(); frame.add(sr); frame.pack(); frame.setVisible(true); } }</code>
위 내용은 Java에서 X축을 중심으로 2D 모양을 회전하고 크기를 조정하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











2025 년 상위 4 개의 JavaScript 프레임 워크 : React, Angular, Vue, Svelte

카페인 또는 구아바 캐시와 같은 라이브러리를 사용하여 자바 애플리케이션에서 다단계 캐싱을 구현하려면 어떻게해야합니까?

Java의 클래스로드 메커니즘은 다른 클래스 로더 및 대표 모델을 포함하여 어떻게 작동합니까?

Spring Boot Snakeyaml 2.0 CVE-2022-1471 문제 고정

캐싱 및 게으른 하중과 같은 고급 기능을 사용하여 객체 관계 매핑에 JPA (Java Persistence API)를 어떻게 사용하려면 어떻게해야합니까?

고급 Java 프로젝트 관리, 구축 자동화 및 종속성 해상도에 Maven 또는 Gradle을 어떻게 사용합니까?
