Hozzászólások
-
SzerzőBejegyzés
-
udv,
a public-ban az „a” mit jelent? a vektort eltarolom tar.x = x, …stb tombokben, de erre hogyan hivatkozok, amikor matrixot akarok belole csinalni?
Code:class Matrix {private:
float tomb[3][3];public:
void Matrix::init(vektor &a, vektor &a){
tomb[0][0] = a.x*a.x;
tomb[1][0] = a.x*a.y;
tomb[2][0] = a.x*a.z;
tomb[0][1] = a.y*a.x;
tomb[1][1] = a.y*a.y;
tomb[2][1] = a.y*a.z;
tomb[0][2] = a.z*a.x;
tomb[1][2] = a.z*a.y;
tomb[2][2] = a.z*a.z;
}teljesen igazad van. de ez most legyen egy kiveteles eset, mert hataridore kellene es igerem neked h tobbet nem zavarlak ilyen kerdesekkel… csak hadd lassam h hogyan nez ki az egesz ugy h mukodik. kerlek…
ha mar ennyit segitettel, akkor legyen mar meg a vege is…:) (lehet h masoknak is tanulsagos lesz…)teljesen igazad van. de ez most legyen egy kiveteles eset, mert hataridore kellene es igerem neked h tobbet nem zavarlak ilyen kerdesekkel… csak hadd lassam h hogyan nez ki az egesz ugy h mukodik. kerlek…
ha mar ennyit segitettel, akkor legyen mar meg a vege is…:) (lehet h masoknak is tanulsagos lesz…)igy van. kedves zolzan22, az lenne a legnagyobb segitseg, ha a vege befejezett lenne (hiszen mar szinte teljesen megvan, csak a vege kellene, ha mar ugy is ennyit segitettel…:)) es akkor lezarhatjuk ezt a topikot.
igy van. kedves zolzan22, az lenne a legnagyobb segitseg, ha a vege befejezett lenne (hiszen mar szinte teljesen megvan, csak a vege kellene, ha mar ugy is ennyit segitettel…:)) es akkor lezarhatjuk ezt a topikot.
renben. a teljesseg kedveert, ha mar ennyit segitettel (es ezert tokre halas vagyok), nem irnad ide a kiiratas reszt. mar ugye minden mas megvan hozza es innen tudnek fejlodni, mert biztos tudnam hogy nem hulyeseg.
es akkor offolhatjuk ezt a temat es megegyszer nagyon koszonom…renben. a teljesseg kedveert, ha mar ennyit segitettel (es ezert tokre halas vagyok), nem irnad ide a kiiratas reszt. mar ugye minden mas megvan hozza es innen tudnek fejlodni, mert biztos tudnam hogy nem hulyeseg.
es akkor offolhatjuk ezt a temat es megegyszer nagyon koszonom…segitenel meg egy kicsit a vege fele?
Code:// for functions rand and srand
#include
//
#include
// input/output stream
#include
// for function time, and for data type time_t
#include
//
#includeusing namespace std;
const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* ——————————————————————– */
bool init_rnd()
{
time_t TIME;
ctime(&TIME);
srand48((unsigned int)(TIME));
return true;
}// Random szamokat general egyenletes eloszlassal (az [a,b[ intervallumon):
double uniform(double a, double b)
{
return a+(b-a)*drand48();
}/* ——————————————————————– */
struct vektor {
float x,y,z;
};class Matrix3x3 {
private:
float tomb[3][3];public:
void Matrix::init(vektor &a, vektor &b){
tomb[0][0] = a.x*b.x;
tomb[1][0] = a.x*b.y;
tomb[2][0] = a.x*b.z;
tomb[0][1] = a.y*b.x;
tomb[1][1] = a.y*b.y;
tomb[2][1] = a.y*b.z;
tomb[0][2] = a.z*b.x;
tomb[1][2] = a.z*b.y;
tomb[2][2] = a.z*b.z;
}Matrix3x3 &operator +=(Matrix3x3 b){
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] += b.tomb[x][y];
return *this;
}Matrix3x3 &operator/=(float c){
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] /= c;
return *this;
}};
/* ——————————————————————– */
int main() {
vektor tar[10];
int i;
for (i=0;i<10;i++) {
float phi = uniform(0.0f, M_2PIf);
float costheta = uniform(-1.0f, 1.0f);
float x = 1.0f * sqrtf(1-costheta*costheta) * cosf(phi);
float y = 1.0f * sqrtf(1-costheta*costheta) * sinf(phi);
float z = 1.0f * costheta;//cout << x << " " << y << " " << z << endl;
tar[i].x = x;
tar[i].y = y;
tar[i].z = z;}
/* ——————————————————————– */
Matrix tar[10];for(i=0; i<10; i++)
tar[i].init(tar[i]);Matrix osszeg = tar[0];
for(i=1; i<10; i++)
osszeg += tar[i];/* ——————————————————————– */
return 0;
}konnyebb lenne megertenem, ha jo lenne… de ezzel szenvedek, Te pedig tok jol vagod…
segitenel meg egy kicsit a vege fele?
Code:// for functions rand and srand
#include
//
#include
// input/output stream
#include
// for function time, and for data type time_t
#include
//
#includeusing namespace std;
const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* ——————————————————————– */
bool init_rnd()
{
time_t TIME;
ctime(&TIME);
srand48((unsigned int)(TIME));
return true;
}// Random szamokat general egyenletes eloszlassal (az [a,b[ intervallumon):
double uniform(double a, double b)
{
return a+(b-a)*drand48();
}/* ——————————————————————– */
struct vektor {
float x,y,z;
};class Matrix3x3 {
private:
float tomb[3][3];public:
void Matrix::init(vektor &a, vektor &b){
tomb[0][0] = a.x*b.x;
tomb[1][0] = a.x*b.y;
tomb[2][0] = a.x*b.z;
tomb[0][1] = a.y*b.x;
tomb[1][1] = a.y*b.y;
tomb[2][1] = a.y*b.z;
tomb[0][2] = a.z*b.x;
tomb[1][2] = a.z*b.y;
tomb[2][2] = a.z*b.z;
}Matrix3x3 &operator +=(Matrix3x3 b){
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] += b.tomb[x][y];
return *this;
}Matrix3x3 &operator/=(float c){
int x,y;
for(x=0; x<3; x++)
for(y=0; y<3; y++)
tomb[x][y] /= c;
return *this;
}};
/* ——————————————————————– */
int main() {
vektor tar[10];
int i;
for (i=0;i<10;i++) {
float phi = uniform(0.0f, M_2PIf);
float costheta = uniform(-1.0f, 1.0f);
float x = 1.0f * sqrtf(1-costheta*costheta) * cosf(phi);
float y = 1.0f * sqrtf(1-costheta*costheta) * sinf(phi);
float z = 1.0f * costheta;//cout << x << " " << y << " " << z << endl;
tar[i].x = x;
tar[i].y = y;
tar[i].z = z;}
/* ——————————————————————– */
Matrix tar[10];for(i=0; i<10; i++)
tar[i].init(tar[i]);Matrix osszeg = tar[0];
for(i=1; i<10; i++)
osszeg += tar[i];/* ——————————————————————– */
return 0;
}konnyebb lenne megertenem, ha jo lenne… de ezzel szenvedek, Te pedig tok jol vagod…
egyebkent valoban, elegge kezdo vagyok, ilyeneket kb. most csinalok eloszor, de sokat tanulok belole es ha segitenek annal hasznosabb a dolog… 🙂
-
SzerzőBejegyzés
legutóbbi hsz