Градусы, минуты, секунды - в градусы:
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translating angle from degrees, minutes, seconds to degrees
// (c) Johna Smith, 1996
//
// Method description:
// Here we just use the following formula:
// phi=(phi"/60+phi')/60+phiш
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
struct angle
{
float degrees;
float minutes;
float seconds;
};
void print_angle(angle a)
{
printf("%fш%f'%f\"",a.degrees,a.minutes,a.seconds);
}
float dms_to_d(angle a)
{
float f;
f=(a.seconds/60+a.minutes)/60+a.degrees;
return f;
}
void main(void)
{
angle a={30,30,30};
print_angle(a);
printf("= %fш",dms_to_d(a));
}
Градусы - в градусы, минуты, секунды:
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translating angle from degrees to degrees, minutes, seconds
// (c) Johna Smith, 1996
//
// Method description:
// degrees is the integer part of angle f
// minutes is the integer part of the remainder multiplied by 60
// seconds is the integer part of 60*(phi_in_minutes-phi')
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
struct angle
{
float degrees;
float minutes;
float seconds;
};
void print_angle(angle a)
{
printf("%fш%f'%f\"",a.degrees,a.minutes,a.seconds);
}
angle d_to_dms(float f)
{
angle a;
a.degrees=(int)f;
a.minutes=(int)((f-a.degrees)*60);
a.seconds=(int)((f-a.degrees)*60-a.minutes);
return a;
}
void main(void)
{
printf("12.3456ш=");
print_angle(d_to_dms(12.3456));
}
Комплексных величин - в экспоненциальную форму
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Complex values operations (converting from a+bi form to M*exp(i*phi))
// (c) Johna Smith, 1996
//
// Given: z - complex value
// z=a+i*b
// z=M*exp(i*phi)
// M=(a^2+b^2)^(1/2) phi=arccos(a/|M|)
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
struct complex
{
float re;
float im;
};
struct exp_complex
{
float M;
float phi;
};
void show_complex(complex c) // this functions displays complex value
{
printf("%f%+fi",c.re,c.im);
}
void show_exp_complex(exp_complex c) // this functions displays complex value
{
printf("%f*exp(%f*i)",c.M,c.phi);
}
exp_complex Convert(complex a)
{
exp_complex b;
b.M=sqrt(a.re*a.re+a.im*a.im);
b.phi=(a.im<0?-1:1)*acos(a.re/fabs(b.M));
return b;
}
complex a={-1,1};
void main(void)
{
show_complex(a);
printf(" = ");
show_exp_complex(Convert(a));
}
Градусы по Фаренгейту - в градусы по Цельсию
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translatintg Farengheit degrees to Celsy degrees and in other direction
// (c) Johna Smith, 1996
//
// Method description:
//
// oF = 5/9(n-32) oC oC = (32+9n/5) oF
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
float Cels2Fareng(float degree)
{
return (5*(degree-32)/9);
}
float Fareng2Cels(float degree)
{
return (32+9*degree/5);
}
void main(void)
{
printf("100oC = %f oF\n",Cels2Fareng(100));
printf("-50oF = %f oC\n",Fareng2Cels(-50));
}
Декартовы координаты - в полярные (2D)
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translatintg Decart coordinates to polar coordinates in 2 dimensions
// (c) Johna Smith, 1996
//
// Method description:
//
// r=(x^2+y^2)^(1/2)
// phi=+/- arccos(x/r)
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
struct decart
{
float x;
float y;
};
struct polar
{
float r;
float phi;
};
polar Decart2Polar(decart c)
{
polar p;
p.r=sqrt(c.x*c.x+c.y*c.y);
p.phi=acos(c.x/p.r)*(c.y>=0?1:-1);
return p;
}
decart d={1,1};
polar p;
void main(void)
{
p=Decart2Polar(d);
printf("(x,y)=(%f,%f) -> (r,phi)=(%f,%f)\n",d.x,d.y,p.r,p.phi);
}
Полярные - в декартовы
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translatintg polar coordinates to Decart coordinates in 2 dimensions
// (c) Johna Smith, 1996
//
// Method description:
//
// x=r*cos(phi)
// y=r*sin(phi)
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
#define Pi 3.1415926536
struct decart
{
float x;
float y;
};
struct polar
{
float r;
float phi;
};
decart Polar2Decart(polar p)
{
decart d;
d.x=p.r*cos(p.phi);
d.y=p.r*sin(p.phi);
return d;
}
polar p={1.4142135624,Pi/4};
decart d;
void main(void)
{
d=Polar2Decart(p);
printf("(r,phi)=(%f,%f) -> (x,y)=(%f,%f)\n",p.r,p.phi,d.x,d.y);
}
Декартовы координаты - в сферические (3D)
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translatintg Decart coordinates to spherical coordinates in 3 dimensions
// (c) Johna Smith, 1996
//
// Method description:
//
// r=(x^2+y^2+z^2)^(1/2)
// phi=+/- arccos(x/(x*x+y*y)^(1/2))
// theta=arccos(z/r)
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
struct decart
{
float x;
float y;
float z;
};
struct spherical
{
float r;
float phi;
float theta;
};
spherical Decart2Spherical(decart c)
{
spherical p;
p.r=sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
p.phi=acos(c.x/sqrt(c.x*c.x+c.y*c.y))*(c.y>=0?1:-1);
p.theta=acos(c.z/p.r);
return p;
}
decart d={1,1,1};
spherical p;
void main(void)
{
p=Decart2Spherical(d);
printf("(x,y,z)=(%f,%f,%f) -> (r,phi,theta)=(%f,%f,%f)\n",
d.x,d.y,d.z,p.r,p.phi,p.theta);
}
Сферические - в декартовы
» Кликните сюда для просмотра оффтоп текста.. «
Код
//////////////////////////////////////////////////////////////////////////////
//
// Translatintg spherical coordinates to Decart coordinates in 3 dimensions
// (c) Johna Smith, 1996
//
// Method description:
//
// x=r*cos(phi)*sin(theta)
// y=r*sin(phi)*sin(theta)
// z=r*cos(theta)
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
#define Pi 3.1415926536
struct decart
{
float x;
float y;
float z;
};
struct spherical
{
float r;
float phi;
float theta;
};
decart Spherical2Decart(spherical p)
{
decart d;
d.x=p.r*cos(p.phi)*sin(p.theta);
d.y=p.r*sin(p.phi)*sin(p.theta);
d.z=p.r*cos(p.theta);
return d;
}
spherical p={1.732051,0.785398,0.955317};
decart d;
void main(void)
{
d=Spherical2Decart(p);
printf("(r,phi,theta)=(%f,%f,%f) -> (x,y,z)=(%f,%f,%f)\n",
p.r,p.phi,p.theta,d.x,d.y,d.z);
}