Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This code converts the cartesian system points to the polar system.
- *
- * @author Daniel Beilin
- * @version Maman12 April 17
- */
- public class Point
- {
- // instance variables - the class gets two points
- /**
- * @param _radius - vector length from 0,0 to x,y
- * @param _alpha - represents the angle of the vector on the X line.
- * @param
- */
- private double _radius;
- private double _alpha;
- private final int DEFAULT_VAL=0;
- private final int DEFAULT_X=0;
- private final int DEFAULT_Y=0;
- public Point(double x, double y) //checks if the paramters are equal or bigger than 0. if not, initializes them as 0.
- {
- if (x<=DEFAULT_VAL)
- {
- x=DEFAULT_X;
- }
- if (y<=DEFAULT_VAL)
- {
- y=DEFAULT_Y;
- }
- _radius = Math.sqrt(Math.pow((x - DEFAULT_X),2)+Math.pow((y - DEFAULT_Y),2));
- _alpha = Math.acos( x / _radius );
- }
- /**
- * Copy constructor for Point
- * constructs a point with same info as other point
- * @param other gets the original points to construct a new copied point
- */
- public Point (Point other)
- {
- _radius = other._radius;
- _alpha = other._alpha;
- }
- private double Round(double d)
- {
- return Math.round(d*10000)/(double)10000);
- }
- /**
- * returns the X variable
- * @return the X coordinate of the point
- */
- public double getX() //לזכור להמיר מרדיאנים למעלות
- {
- if (_alpha == (Math.PI/2));{
- return 0;
- }
- return Math.cos (_alpha * _radius);
- }
- /**
- * returns the Y variable
- * @return the Y coordinate of the point
- */
- public double getY()
- {
- if (_alpha == (Math.PI/2));{
- return 0;
- }
- return Math.sin( _alpha * _radius);
- }
- /**
- * Sets the X coordinate of the point
- * if it receives a number smaller than 0, then X doesn't change
- * @param x the new X coordinate
- */
- public void setX(double x)
- {
- if (x<=DEFAULT_VAL)
- x = DEFAULT_X;
- _alpha = Math.tan (getY() * x);
- _radius = Math.sqrt(Math.pow((getX() - DEFAULT_X),2)+Math.pow((getY() - DEFAULT_Y),2));
- }
- /**
- * Sets the Y coordinate of the point
- * if it receives a number smaller than 0, then Y doesn't change
- * @param x the new Y coordinate
- */
- public void setY(double y)
- {
- if (y<=DEFAULT_VAL)
- y = DEFAULT_Y;
- _alpha = Math.sin (getX() * y);
- _radius = Math.sqrt(Math.pow((getX() - DEFAULT_X),2)+Math.pow((getY() - DEFAULT_Y),2));
- }
- /**
- * returns a string with the point values
- * @return String values
- */
- public String toString()
- {
- return "(" + getX() + "," + getY() + ")";
- }
- /**
- * Checks if the point is equal to the other point
- * @other the point to compare to
- * @return true if the points are equal
- */
- public boolean equals(Point other)
- {
- return (other._radius == _radius && other._alpha == _alpha);
- }
- /**
- * Checks if the point is above other point
- * @param Other the other point to compare to
- * @return true if point is above other point.
- */
- //public boolean isAbove(Point other)
- /*
- * Checks if the point is under other point
- * @param Other the other point to compare to
- * @return true if point is under other point
- public boolean isUnder(Point other)
- {
- return (other.isAbove(this));
- }
- /**
- * Checks if point is left to other
- * @param the point to compare to
- * @return true if the point is left to other point
- public boolean isLeft(Point other)
- {
- return (other._x > _x);
- }
- /**
- * Checks if point is right to other
- * @param the point to compare to
- * @return true if the point is right to other point
- *
- public boolean isRight(Point other)
- {
- return (other.isLeft(this));
- }
- public double distance(Point p)
- {
- return Math.sqrt(Math.pow((_x - p._x),2)+Math.pow((_y - p._y),2));
- }
- /*
- * Moves the x coordinate by dx and the y by dy
- * if it moves the points outside the first quarter, then the point will stay the same
- * @param dX, the amount to move X
- * @param dY, the amount to move Y
- *
- public void move (double dX, double dY)
- {
- if ((_x + dX) >= 0 && (_y + dY) >= 0)
- {
- setX(_x + dX);
- setY(_y + dY);
- }
- }
- public double getRadius()
- {
- return _radius;
- }
- public double setRadius(double x, double y)
- {
- _radius = Math.sqrt(Math.pow((_x - x),2)+Math.pow((_y - y),2));
- return _radius;
- }
- public double getAlpha()
- {
- return _alpha;
- }
- */
- } //class Point
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement