Returns the x,y coordinates of the end point of line starting at startx, starty in the direction of the given heading and of the given length. - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

Returns the x,y coordinates of the end point of line starting at startx, starty in the direction of the given heading and of the given length.

Demo Code

/*//from w w w. j av  a 2 s  .  co m
 * Copyright (c) 2001-2002 Regents of the University of California.
 * All rights reserved.
 *
 * This software was developed at the University of California, Irvine.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the University of California, Irvine.  The name of the
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
//package com.java2s;

import java.awt.Point;

public class Main {
    /**
     * Returns the x,y coordinates of the end point of line starting
     * at startx, starty in the direction of the given heading and of 
     * the given length.
     */
    public static Point getHeadingEndPoint(int startx, int starty,
            int heading, int length) {
        int x, y;
        x = startx + (int) (Math.cos(Math.toRadians(heading)) * length);
        y = starty - (int) (Math.sin(Math.toRadians(heading)) * length);
        return new Point(x, y);
    }
}

Related Tutorials