calculate angles

edited April 2014 in Programming Questions

Hi, i have the following question: i have a triangle with a 90° angle and want to calculate Alpha. How can I do this? Please help me

Answers

  • I diagram would be helpful, not sure what alpha in the context of a right triangle

  • i found this too, but i want to calculate an angle, what they don't do in this tutorial...

  • Depends what you have: how many sides and angles you know.....

  • edited April 2014

    If you have 3 angles (which I'm guessing you don't) you do CosX=a^2+b^2-2abCosC. If you have at least an angle and a side and 2 others, if you post them and I'll tell you what to do (it's a bit complicated to explain). :) Hope I can help

  • If a diagram is not a comfortable method to explain a problem, you could explain it taking some other example or in simple words.

    This link shows the basic needs you might need to fulfill http://processing.org/tutorials/trig/

    Shadab K

    Weave and Connect

  • oh yes. i see. sorry.

    but checkout this chapter of the the nature of code book: http://natureofcode.com/book/chapter-3-oscillation/

    especially chapter 3.4

  • In my opinion this question is not solved in the tutorial

    here...

    int angle; 
    int radius = 70;
    
    int centerX=200;
    int centerY=200;
    
    
    void setup() {
      size(700, 700);
      background(110);
    }
    
    void draw() {
      background(110, 11);
    
      float moveX = radius * sin(radians(angle))+centerX;
      float moveY = -radius * cos(radians(angle))+centerY;
    
      float moveX2 = radius * sin(radians(angle))+0;
      float moveY2 = -radius * cos(radians(angle))+0;
    
      float angle2 =   atan2(moveY2, moveX2);
    
      angle2 = map (angle2-HALF_PI, -PI, PI, 
      0, TWO_PI);
    
      // white point 
      stroke(255);
      fill(255, 2, 2);
      point(moveX, moveY);
    
      // 2 green lines 
      stroke(0, 111, 0);
      line (moveX, centerY, centerX, centerY);
      line (centerX, centerY, centerX, moveY);
    
      // display text : angle 
      fill(110);
      noStroke();
      rect (width-200, height-200, 200, 200);
      fill(0);
      stroke(0);
      text ("angle: " 
        + angle + "\n"
        + moveX+","
        + moveY, width-100, height-100);
    
    
      print(angle +", ");
      float result=degrees(angle2)+0; 
      if (result<0) 
        result=result+360;
      int result2 = int (round(result));
      if (result2!=  angle) 
        print ("wrong: ");
    
      println(result2);
    
      // increase 
      angle++;
    }
    
  • edited April 2014

    my solution uses opposite side and adjacent side (between those is the right angle) to calculate the angle named θ

    see the tutorial, 1st image, for these namings I use

    http://processing.org/tutorials/trig/

  • my solution is not short nor elegant...

Sign In or Register to comment.