title: Calculate x y of Point after increasing distance
body: <p>I am trying to get the x and y value of a point after increasing the distance r. Perhaps there is a better way of calculate the angle phi too, so that I don't need to check in which quadrant the point is. The 0-point is at the half of the width and height of the window. Here is my attempt:</p>
  
  <pre><code>package test;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Point;
  
  public final class Laser extends java.applet.Applet implements Runnable{
  
  private static final long serialVersionUID = -7566644836595581327L;
  
  Thread runner;
  
  int width = 800;
  int height = 600;
  
  Point point = new Point(405,100);
  Point point1 = new Point(405,100);
  
  public void calc(){
  
      int x = getWidth()/2;
      int y = getHeight()/2;
      int px = point.x;
      int py = point.y;
      int px1 = point1.x;
      int py1 = point1.y;
      double r = 0;
      double phi = 0;
  
      // Point is in:
      // Quadrant 1
      if(px &gt; x &amp;&amp; py &lt; y){
          r = Math.hypot(px1-x, y-py1);
          phi = Math.acos((px1-x)/r)*(180/Math.PI);
      }/*
      // Quadrant 2
      else if(px &lt; x &amp;&amp; py &lt; y){
          r = Math.hypot(x-px, y-py);
          phi = Math.acos((px-x)/r)*(180/Math.PI);
      }
      // Quadrant 3
      else if(px &lt; x &amp;&amp; py &gt; y){
          r = Math.hypot(x-px, py-y);
          phi = Math.acos((px-x)/r)*(180/Math.PI)+180;
      }
      // Quadrant 4
      else if(px &gt; x &amp;&amp; py &gt; y){
          r = Math.hypot(px-x, py-y);
          phi = Math.acos((px-x)/r)*(180/Math.PI)+180;
      }*/
      r += 1;
      point1.x = (int) (r*Math.cos(phi));
      point1.y = (int) (r*Math.sin(phi));
      System.out.println(r+";"+point1.x+";"+point1.y);
  
  }
  
  public void paint(Graphics g) {
  
      g.setColor(Color.ORANGE);
      calc(); 
      g.drawLine(point.x, point.y, point1.x, point1.y);
  
      int h = getHeight();
      int w = getWidth();
      g.setColor(Color.GREEN);
      g.drawLine(0, h/2, w, h/2);
      g.drawLine(w/2, 0, w/2, h);
  
  }
  /*
  public void initPoints(){
  
      for(int i = 0; i &lt; pointsStart.length; i++){
          int x = (int)(Math.random()*getWidth());
          int y = (int)(Math.random()*getHeight());
          pointsStart[i] = pointsEnd[i] = new Point(x,y);
      }
  
  }
  */
  public void start() {
  
      if (runner == null) {
  
          runner = new Thread(this);
          setBackground(Color.black);
          setSize(width, height);
          //initPoints();
          runner.start();
  
      }
  
  }
  
  @SuppressWarnings("deprecation")
  public void stop() {
  
      if (runner != null) {
  
          runner.stop();
  
          runner = null;
  
      }
  
  }
  
  
  public void run() {
  
      while (true) {
  
          repaint();
  
          try { Thread.sleep(700); }
  
          catch (InterruptedException e) { }
  
      }
  
  }
  
  public void update(Graphics g) {
  
      paint(g);
  
  }
  
  }
  </code></pre>