A little math help....

Hi all,
I am working on a new arduino project, and i needed some help with the math. I've got the software skills to implement this function, but I am getting a little confused on the math. I drew a picture of what I am trying to do:
http://s21.postimg.org/nyctfqr13/arduino_representation.png

essentially, there are servos at angles A and B
distance X is determined by a sensor
I am trying to create an arduino function that would be able to determine angle measurements based on the distance. "invisible" point C (the point not labeled by an angle) and point A are always at the same vertical height (8 cm).

Any help would be greatly appreciated. If you need more data, please ask.
TechnoD11

I have drawn a new picture. Please show this new picture with:

3 angles ABC
3 points abc
fourth point 8cm below a called d

sides :
da = 8cm
ac = 14cm
ab = 9.5cm
bc?
db ?
cd?

There are 2 right angles at d

When you label your diagram using standard mathematical symbols as above, we can go to the next steps:
Pythagorean Theorem
law of sines
law of cosines

Since you know three sides (14 cm, 9.5 cm, and X) you can calculate the three angles:

The angles of a triangle always add up to 180o.
(Before anyone argues about triangles on the surface of a sphere, I'm talking about planar triangles.)
Therefore, Angle C = 180o -Bo -Ao.
No need for anything more complicated than that.

Henry_Best:
Therefore, Angle C = 180o -Bo -Ao.
No need for anything more complicated than that.

Unfortunately Angle A and Angle B are the UNKNOWNS he is trying to solve for. :frowning:

I calculated the angle B as 57.296 degrees.
B is one radian.
A will be calculated if TechnoD11 asks.

AmbiLobe:
I calculated the angle B as 57.296 degrees. B is one radian.

How did you calculate the angle B given only two sides of the triangle?

I drew a diagram to label all points and all angles.
I used the Pythagorean Theorem to get all side lengths.
The bottom side is 16.612
I used the Law of Cosines to get angle B. (called A in the original diagram, sorry).

Would you like to see the equation for B, combining all laws and theorems?

AmbiLobe:
I used the Pythagorean Theorem to get all side lengths.

That would only be valid if you knew that this was a right angled triangle, which I don't think is the case here.

You can work this out using Pythagoras' theorem if you divide one of the sides to produce TWO right angled triangles and then solve those as simultaneous equations.

The original post describes an invisible point 8cm from something. I drew a new diagram calling the point d. There are 2 right angles at point d. I will draw a diagram, photograph it and show it to you.

Here is what the original description says, ""invisible" point C (the point not labeled by an angle) and point A are always at the same vertical height (8 cm). "

In other words, the bottom line is 8cm below point B (labeled Angle B) on the primitive diagram. I drew a vertical line from B to the bottom horozontal line and called that point d. Two right angles are at point d.

New diagram:

Angle A is one radian (57 degrees).

I'm not sure if I understand you correctly but from what I get basically you have a triangle and you know three sides:

9.5 cm
14 cm
x cm

And from what I understand you want to know the angles? For points A, B and C.

Basically you need to have it like

angle C = arccos ((14^2+x^2-9.5^2)/(2*9.5*14))

I think, I kinda just woke up so a bit out of it, but thats what I understand.

Might be worth checking out the "Sine, cosine and tangent rules"
on wiki Triangle - Wikipedia

Hi, check the Law of Sines to see if it suits your request: Law of sines - Wikipedia.

Hello and thanks all for the help so far. I have been looking through the various answers and doing a bit more searching on the internet and I created this code, which allows me to change the 'x' variable by increments of 1. the code is sort of rudimentary (and probably has a lot of unnecessary parenthesis), but the math looked sound to me. Here it is:

#include <math.h>
/* Servo definitions and values
#include <Servo.h>
Servo bot;
Servo mid;
*/
int distance = 20;
float pi = 3.1416;  //I don't need anything more detailed than that
//cos radian angles
double angleA = 0;
double angleB = 0;
// arc cos radian angles
float arcangleA = 0;
float arcangleB = 0;
//degrees angles
float degangleA = 0;
float degangleB = 0;
float degangleC = 0;
//Serial val
char val = 0;

void setup(){
	Serial.begin(9600);
	/*attach servos
	bot.attach(4);
	mid.attach(2);
	*/
}
void loop(){
	if(Serial.available()){;}
		val = Serial.read();
	if(val == '+'){
		distance = distance + 1;
	}
	if(val == '-'){
		distance = distance - 1;
	}
	//radian cos logic
	angleA = ((196 + ((distance)^2) - 100)/(28 * (distance)));
	angleB = ((((distance)^2) - 96)/(20 * (distance)));
	//radian arc cos logic
	arcangleA = acos(angleA);
	arcangleB = acos(angleB);
	//conversion to degrees
	degangleA = ((arcangleA * 180)/(pi));
	degangleB = ((arcangleB * 180)/(pi));
	//calculation of C angle
	degangleC = (180 - (degangleA + degangleB));

	Serial.print("degangleB:");
	Serial.println(degangleB);
	Serial.print("degangleC:");
	Serial.println(degangleC);
	delay(1000);
}

You might recognize the #include <math.h> at the top, that's a library I found from here:

acos() is arccos(), and the output is in radians (hence the conversion).
Anyway, after finally getting all this onto my arduino board (which is a nano v3.0 by the way), I got this in the serial monitor:
degangleC:0.00
degangleB:90.00
degangleC:0.00
degangleB:90.00
degangleC:0.00
degangleB:90.00
and so on...
changing the distance value with +/- didn't do anything

any help on math/software/etc would be helpful
thx again for all the help so far.
*edit
my apologies, I forgot to mention that I miscalculated a bit, the lengths of the two triangle sides are actually 14 cm and 10 cm, not 14.5 cm and 9.5 cm.

I want to help. Do you approve of the new triangle picture? Did I make an error in that new picture?

You should write a specification for your software :
Output result needed : ?
What is the output from the program that you want? An angle? Two angles?

@Ambilobe:

  1. the output I am looking for is 2 angle measures, angles B and C (in my software and in picture below).
  2. Your picture is a bit off, but that's not your fault, that's me giving a bad description. I took a little more time and created a more accurate picture which can be found here:
    http://s24.postimg.org/4jaojq41x/arduino_representation_2.png
    Notes:
    Point (angle) B is fixed, horizontally and vertically
    Point (angle) A is fixed only vertically
    What I am looking for is, without moving point B at all or point A vertically, what are the angle measures for angles B and C, given side length X (read from a sensor)
    The triangle is not "fixed", its "fluid", in that the shape of the triangle will change based on the value of X.

I hope this helps.

The answer is the same as before. You know the length of all three sides of a triangle (14, 10, and X). You use the formulas I pointed to to calculate all the angles:

@Johnwasser
I already made the corrections when i put the code up a few posts back, that code has the values of 10 and 14, not the previous values. so the issue still stands.

TechnoD11:
@Johnwasser
I already made the corrections when i put the code up a few posts back, that code has the values of 10 and 14, not the previous values. so the issue still stands.

In your code seems to be written assuming "^2" will square a number. Unfortunately for you the '^' operator is bitwise exclusive-OR, not 'raise to a power'. Try "distance*distance" in place of "distance^2", etc.

Well then....didn't realize arduino didn't do powers. that would explain a lot. thanks, I'll post back tomorrow what I get.