Android Open Source - NotATop Line






From Project

Back to project page NotATop.

License

The source code is released under:

GNU General Public License

If you think the Android project NotATop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gg.util;
//from w w w .j  av  a  2 s. c o m
/*    ????????????    */
public class Line {

  private Point firstPoint;
  private Point secondPoint;
  
  private Direction direction;
  private float k;
  private float b;

  public Line(){
    
  }
  
  public Line(Point first, Point second){
    firstPoint = first;
    secondPoint = second;
    
    direction = calculateDirection(firstPoint, secondPoint);
    
    k = (secondPoint.y-firstPoint.y) / (secondPoint.x-firstPoint.x);
    b = firstPoint.y - k*firstPoint.x;
  }
  
  public Line(float x1, float y1, float x2, float y2){
    this(new Point(x1, y1, 0f), new Point(x2, y2, 0f));
  }

  
  /*    ?????get(),set()    */
  public Point getFirstPoint() {
    return firstPoint;
  }

  public void setFirstPoint(Point firstPoint) {
    this.firstPoint = firstPoint;
  }

  public Point getSecondPoint() {  
    return secondPoint;  
  }

  public void setSecondPoint(Point secondPoint) {
    this.secondPoint = secondPoint;
  }

  public Direction getDirection() {
    return direction;
  }

  public void setDirection(Direction direction) {
    this.direction = direction;
  }
  
  public float getB() {
    return b;
  }

  public void setB(float b) {
    this.b = b;
  }

  public float getK() {
    return k;
  }

  public void setK(float k) {
    this.k = k;
  }

  

  public Direction calculateDirection(Point firstPoint, Point secondPoint){
    if(secondPoint.x > firstPoint.x){
      if(secondPoint.y > firstPoint.y){
        return new Direction(Direction.UP_RIGHT);
      }else if(secondPoint.y < firstPoint.y){
        return new Direction(Direction.DOWN_RIGHT);
      }else{
        return new Direction(Direction.RIGHT);
      }
    }else if(secondPoint.x < firstPoint.x){
      if(secondPoint.y > firstPoint.y){
        return new Direction(Direction.UP_LEFT);
      }else if(secondPoint.y < firstPoint.y){
        return new Direction(Direction.DOWN_LEFT);
      }else{
        return new Direction(Direction.LEFT);
      }
    }else{
      if(secondPoint.y > firstPoint.y){
        return new Direction(Direction.UP);
      }else{
        return new Direction(Direction.DOWN);
      }
    }
  }

  
  public boolean isCollideCircle(Circle circle){
    float r = circle.getRadius();
    float distance = distanceCircle(circle);
    
    if(distance > r){
      return false;
    }else if(distance == r){
      return true;
    }else{  
      return true;

    }
  }
  
  
  public float distanceCircle(Circle circle){
    float x0 = circle.getCenter().x;
    float y0 = circle.getCenter().y;
    return (float) (Math.abs(y0-k*x0-b) / Math.sqrt(1+k*k));
  }
  
  
  public Direction directionCircle(Circle circle){
    float x0 = circle.getCenter().x;
    float y0 = circle.getCenter().y;
    float circleB = y0 - k*x0;
    
    if(circleB>b){
      return new Direction(Direction.DOWN);
    }else if(circleB<b){
      return new Direction(Direction.UP);
    }else{
      return new Direction(Direction.RIGHT);
    }
  }
  
}




Java Source Code List

com.gg.game.ClassicGame.java
com.gg.game.ClassicGame.java
com.gg.game.GameFrame.java
com.gg.game.GameFrame.java
com.gg.game.TimeGame.java
com.gg.game.TimeGame.java
com.gg.module.DrawBackground.java
com.gg.module.DrawBackground.java
com.gg.module.DrawScore.java
com.gg.module.DrawScore.java
com.gg.module.DrawTrack.java
com.gg.module.DrawTrack.java
com.gg.module.SelectControl.java
com.gg.module.SelectControl.java
com.gg.module.SoundControl.java
com.gg.module.SoundControl.java
com.gg.module.VoiceControl.java
com.gg.module.VoiceControl.java
com.gg.top.BasicTop.java
com.gg.top.BasicTop.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCone.java
com.gg.top.DrawCone.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawTop.java
com.gg.top.DrawTop.java
com.gg.util.Circle.java
com.gg.util.Circle.java
com.gg.util.Constant.java
com.gg.util.Constant.java
com.gg.util.DateUtil.java
com.gg.util.DateUtil.java
com.gg.util.Direction.java
com.gg.util.Direction.java
com.gg.util.Line.java
com.gg.util.Line.java
com.gg.util.Point.java
com.gg.util.Point.java
com.gg.util.TextureRect.java
com.gg.util.TextureRect.java
com.gg.util.TrackPoint.java
com.gg.util.TrackPoint.java
com.gg.util.Track.java
com.gg.util.Track.java
com.gg.util.Utils.java
com.gg.util.Utils.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.MainActivity.java
com.gg.view.MainActivity.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.WelcomeSurfaceView.java
com.gg.view.WelcomeSurfaceView.java