Java Graphics Draw drawAngledLine(Graphics g, int x, int y, double angle, int length)

Here you can find the source of drawAngledLine(Graphics g, int x, int y, double angle, int length)

Description

draws a line starting at x,y, and going in the direction of the angle

License

Open Source License

Declaration

public static void drawAngledLine(Graphics g, int x, int y, double angle, int length) 

Method Source Code


//package com.java2s;
/* Mesquite source code.  Copyright 1997 and onward, W. Maddison and D. Maddison. 
    /*from  w w w .  j a v  a 2  s  .  c  om*/
    
Disclaimer:  The Mesquite source code is lengthy and we are few.  There are no doubt inefficiencies and goofs in this code. 
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
    
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
    
This source code and its compiled class files are free and modifiable under the terms of 
GNU Lesser General Public License.  (http://www.gnu.org/copyleft/lesser.html)
 */

import java.awt.*;

public class Main {
    /** draws a line starting at x,y, and going in the direction of the angle */
    public static void drawAngledLine(Graphics g, int x, int y, double angle, int length) {
        int endX = (int) (Math.cos(angle) * length) + x;
        int endY = (int) (Math.sin(angle) * length) + y;
        g.drawLine(x, y, endX, endY);
    }
}

Related

  1. draw(int[] pixels, int width, int height)
  2. drawAndFill(Graphics g, Shape s, Color draw, Color fill)
  3. drawAt(final Graphics2D g, final double x, final double y, final Shape s)
  4. drawAutoCompleteMarker(Graphics2D g2, int x, int y, int iconSize)
  5. drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright, boolean showMirror, boolean isDichroic)
  6. drawBeamVariableRadiusVertical(Graphics g, Color c, int midx, int y1, int y2, int r1, int r2)