2 Replies - 157 Views - Last Post: 29 May 2019 - 02:44 PM Rate Topic: -----

#1 darkace79   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 03-October 13

Trouble calculating length and an angle

Posted 29 May 2019 - 10:29 AM

I am trying to find the length of edges and then I try to find an angle. The edges always seem to be the same length even though they have different points. Trying to compare lengths of an Edge which the edge points are stored in an array. Seem to be going in circles here.

....

I found my issue.

This post has been edited by darkace79: 29 May 2019 - 12:20 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Trouble calculating length and an angle

#2 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 775
  • View blog
  • Posts: 5,836
  • Joined: 25-December 13

Re: Trouble calculating length and an angle

Posted 29 May 2019 - 10:55 AM

Can you explain the algorithm in English that you are trying to implement in code?
Post some example equations that show what you are trying to calculate.

What is the definition/declaration for the variable: edges?

This post has been edited by NormR: 29 May 2019 - 11:46 AM

Was This Post Helpful? 0
  • +
  • -

#3 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 775
  • View blog
  • Posts: 5,836
  • Joined: 25-December 13

Re: Trouble calculating length and an angle

Posted 29 May 2019 - 02:44 PM

The posted code:

       public double getAngleBetween(Edge edge2) {
   		Vector2d v1 = getVector();
   		Vector2d v2 = edge2.getVector();
   		
   		return v1.angle(v2) * 180 / Math.PI;
   	}
   	
    private Vector2d getVector() {
    	Vector2d vec = new Vector2d(end.getX() - start.getX(), end.getY() - start.getY()); 
    	vec.normalize();
    	return vec;
      }
 
    public double getLength() {
		double x = Math.abs(end.getX() - start.getX());
		x *= x;
		double y = end.getY() - start.getY();
		y *= y;
		double length = Math.sqrt(x + y);
		return length;
	}

   angleBetween = edges[0].getAngleBetween(edges[3]);

		double edge1 = edges[0].getLength();
		double edge2 = edges[1].getLength();
		double edge3 = edges[2].getLength();
		double edge4 = edges[3].getLength();
		double tol = 0.001;
		
		if ((Math.abs(edge1 - edge2) <= tol) && (Math.abs(edge2 - edge3) <= tol)
				&& (Math.abs(edge3 - edge4) <= tol) && (Math.abs(edge4 - edge1) <= tol) && angleBetween == 90) {
			shape = "square";
		} else if ((Math.abs(edge1 - edge3) <= tol) && (Math.abs(edge2 - edge4) <= tol) && angleBetween == 90) {
			shape = "rectangle";
		}else 
			shape = "quadrilateral";


Can you post what the issue was and how you fixed it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1