JavaFX draw Line At Angle - Java JavaFX

Java examples for JavaFX:Canvas

Description

JavaFX draw Line At Angle

Demo Code


//package com.java2s;

import java.awt.Graphics2D;

import javafx.scene.canvas.GraphicsContext;

public class Main {
    public static void drawLineAtAngle(GraphicsContext gc, double x1,
            double y1, double length, double angle) {
        gc.strokeLine(x1, y1,// ww  w .  ja v a2 s  . c  o  m
                x1 + length * Math.cos(Math.toRadians(angle)), y1 + length
                        * Math.sin(Math.toRadians(angle)));
    }

    public static void drawLineAtAngle(Graphics2D g2d, double x1,
            double y1, double length, double angle) {
        g2d.drawLine((int) x1, (int) y1,
                (int) (x1 + length * Math.cos(Math.toRadians(angle))),
                (int) (y1 + length * Math.sin(Math.toRadians(angle))));
    }
}

Related Tutorials