trigonometical,rad,acos... HELP please

A

apropo

this function should return the degrees of the (AOB) angle. I tested it on a
value of 30° and it returned 36,869896, with the points declaration:
a.x=0;a.y=0;
b.x=3;b.y=4;
c.x=0;c.y=4;
and the call to the function:
alfa =winkelgroesse(b,a,c);
here is it:

float winkelgroesse(punkt m,punkt o,punkt n){ float a,b,c,alfa;
c=powf(m.x-n.x,2)+powf(m.y-n.y,2);
a=sqrtf(powf(o.x-n.x,2)+powf(o.y-n.y,2));
b=sqrtf(powf(o.x-m.x,2)+powf(o.y-m.y,2));
alfa=acosf((powf(a,2)+powf(b,2)-c)/(2*a*b));
alfa=180*alfa/PI;
return alfa; }

did i make a mistake at converting rad to degrees ?
 
R

Rouben Rostamian

this function should return the degrees of the (AOB) angle. I tested it on a
value of 30° and it returned 36,869896, with the points declaration:
a.x=0;a.y=0;
b.x=3;b.y=4;
c.x=0;c.y=4;
and the call to the function:
alfa =winkelgroesse(b,a,c);
here is it:

float winkelgroesse(punkt m,punkt o,punkt n){ float a,b,c,alfa;
c=powf(m.x-n.x,2)+powf(m.y-n.y,2);
a=sqrtf(powf(o.x-n.x,2)+powf(o.y-n.y,2));
b=sqrtf(powf(o.x-m.x,2)+powf(o.y-m.y,2));
alfa=acosf((powf(a,2)+powf(b,2)-c)/(2*a*b));
alfa=180*alfa/PI;
return alfa; }

The 36,869896 (36.869896 for Americans) is correct, as it is the
size of the angle "o" in the triange that you have specified.

Why are you expecting of 30°?
 
M

Merrill & Michele

apropo said:
this function should return the degrees of the (AOB) angle. I tested it on a
value of 30° and it returned 36,869896, with the points declaration:
a.x=0;a.y=0;
b.x=3;b.y=4;
c.x=0;c.y=4;
and the call to the function:
alfa =winkelgroesse(b,a,c);
here is it:

float winkelgroesse(punkt m,punkt o,punkt n){ float a,b,c,alfa;
c=powf(m.x-n.x,2)+powf(m.y-n.y,2);
a=sqrtf(powf(o.x-n.x,2)+powf(o.y-n.y,2));
b=sqrtf(powf(o.x-m.x,2)+powf(o.y-m.y,2));
alfa=acosf((powf(a,2)+powf(b,2)-c)/(2*a*b));
alfa=180*alfa/PI;
return alfa; }

did i make a mistake at converting rad to degrees ?

Und wie geht das in die andere Rictung? Es werden degrees gegeben und Sie
wollen rads. MPJ
 
M

Martin Ambuhl

apropo said:
this function should return the degrees of the (AOB) angle. I tested it on a
value of 30° and it returned 36,869896, with the points declaration:
a.x=0;a.y=0;
b.x=3;b.y=4;
c.x=0;c.y=4;

Well, why did you think a 3-4-5 triangle has any 30 degree angles in it?
and the call to the function:
alfa =winkelgroesse(b,a,c);
here is it:

float winkelgroesse(punkt m,punkt o,punkt n){ float a,b,c,alfa;
c=powf(m.x-n.x,2)+powf(m.y-n.y,2);
a=sqrtf(powf(o.x-n.x,2)+powf(o.y-n.y,2));
b=sqrtf(powf(o.x-m.x,2)+powf(o.y-m.y,2));
alfa=acosf((powf(a,2)+powf(b,2)-c)/(2*a*b));
alfa=180*alfa/PI;
return alfa; }

did i make a mistake at converting rad to degrees ?

You misspecified the triangle.

#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846L

typedef struct
{
double x, y;
} punkt;

inline double square(double x)
{
return x * x;
}

double winkelgroesse(punkt m, punkt o, punkt n)
{
double a, b, c;
c = square(m.x - n.x) + square(m.y - n.y);
a = square(o.x - n.x) + square(o.y - n.y);
b = square(o.x - m.x) + square(o.y - m.y);
return 180 * acos((a + b - c) / (2 * sqrt(a * b))) / PI;
}

int main(void)
{
punkt a, b, c;
double alfa;
a.x = 0;
a.y = 0;
b.x = sqrt(3);
b.y = 0;
c.x = sqrt(3);
c.y = 1;
alfa = winkelgroesse(b, a, c);
printf("alfa = %g\n", alfa);
}

[output]
alfa = 30
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top