Kezdőlap › Fórumok › Programozás › matrix osztaly osszeadasra
- This topic has 178 hozzászólás, 8 résztvevő, and was last updated 17 years, 4 months telt el by
uzsolt.
-
SzerzőBejegyzés
-
2008-02-24-14:31 #2154689
Nekem eddig igy nez ki:
Code:#include
#include
#include
#include
#include
using namespace std;const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* —————–RANDOM_GENERATOR———————————– */
float rand(float min, float max)
{
return min + (max – min) * rand() / (float)RAND_MAX;
}struct vektor {
float x,y,z;
};/* ——————MATRIX_OSZTALY———————————— */
class Matrix {
private:
float tomb[3][3];public:
void Matrix::init(vektor &a){
tomb[0][0] = a.x * a.x;
tomb[0][1] = a.x * a.y;
tomb[0][2] = a.x * a.z;
tomb[1][0] = a.y * a.x;
tomb[1][1] = a.y * a.y;
tomb[1][2] = a.y * a.z;
tomb[2][0] = a.z * a.x;
tomb[2][1] = a.z * a.y;
tomb[2][2] = a.z * a.z;
}Matrix &operator +=(Matrix m){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] += m.tomb[k][l];
return *this;
}Matrix &operator/=(float c){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] /= c;
return *this;
}};
/* ——————————————————————– */
int main() {
vektor tar[1000];
int i;for (i=0;i<1000;i++) {
float phi = rand(0.0f, M_2PIf);
float costheta = rand(-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;tar[I].x = x;
tar[I].y = y;
tar[I].z = z;
//cout << tar[1].x << " " << tar[1].y << " " << tar[1].z << endl;
}[I][I][I]//system ("PAUSE");
return 0;
}Tehat definialva vannak a matrix osszeadasi, osztasi muveletek; megvan a random generalas is es egy vektor matrixa alakitasa.
Ezt a matrix atalakitast nem nagyon ertem; gondolom egy for ciklussal kellene ezeket osszeadni, csak az erre valo hivatkozast nem tudom (a kod)…
[/I][/I][/I][/I][/I][/I]
2008-02-24-14:31 #2154690Nekem eddig igy nez ki:
Code:#include
#include
#include
#include
#include
using namespace std;const float M_2PIf = 6.283185307179586476925286766559f;
const float M_PIf = 3.141592653589793238462643383279f;/* —————–RANDOM_GENERATOR———————————– */
float rand(float min, float max)
{
return min + (max – min) * rand() / (float)RAND_MAX;
}struct vektor {
float x,y,z;
};/* ——————MATRIX_OSZTALY———————————— */
class Matrix {
private:
float tomb[3][3];public:
void Matrix::init(vektor &a){
tomb[0][0] = a.x * a.x;
tomb[0][1] = a.x * a.y;
tomb[0][2] = a.x * a.z;
tomb[1][0] = a.y * a.x;
tomb[1][1] = a.y * a.y;
tomb[1][2] = a.y * a.z;
tomb[2][0] = a.z * a.x;
tomb[2][1] = a.z * a.y;
tomb[2][2] = a.z * a.z;
}Matrix &operator +=(Matrix m){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] += m.tomb[k][l];
return *this;
}Matrix &operator/=(float c){
int k,l;
for(k=0; k<3; k++)
for(l=0; l<3; l++)
tomb[k][l] /= c;
return *this;
}};
/* ——————————————————————– */
int main() {
vektor tar[1000];
int i;for (i=0;i<1000;i++) {
float phi = rand(0.0f, M_2PIf);
float costheta = rand(-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;tar[I].x = x;
tar[I].y = y;
tar[I].z = z;
//cout << tar[1].x << " " << tar[1].y << " " << tar[1].z << endl;
}[I][I][I]//system ("PAUSE");
return 0;
}Tehat definialva vannak a matrix osszeadasi, osztasi muveletek; megvan a random generalas is es egy vektor matrixa alakitasa.
Ezt a matrix atalakitast nem nagyon ertem; gondolom egy for ciklussal kellene ezeket osszeadni, csak az erre valo hivatkozast nem tudom (a kod)…
[/I][/I][/I][/I][/I][/I]
2008-02-25-15:45 #2154691Asszem megvan. Csak hogyan irathatom ki? Please help!
Valami ilyesmi kellene a class-ba?
Code:std::ostream& operator<<(std::ostream& output, valami) {
output << "[n";
for (i=0,i<5,i++) {output << " " << valami << " ";
output << "n";
}
output << "]";return output;
}2008-02-25-15:45 #2154692Asszem megvan. Csak hogyan irathatom ki? Please help!
Valami ilyesmi kellene a class-ba?
Code:std::ostream& operator<<(std::ostream& output, valami) {
output << "[n";
for (i=0,i<5,i++) {output << " " << valami << " ";
output << "n";
}
output << "]";return output;
}2008-02-25-19:07 #2154693Nos? Tudna valaki segiteni?
2008-02-25-19:07 #2154694Nos? Tudna valaki segiteni?
2008-02-25-19:24 #2154695Valoszinuleg tudna.
Azert elore szolok, hogy el akarod bonyolitani a kiiratast.2008-02-25-19:24 #2154696Valoszinuleg tudna.
Azert elore szolok, hogy el akarod bonyolitani a kiiratast.2008-02-25-19:31 #2154697Jo. Akkor nem tudnal segiteni, ez mar tenyleg csak a vege. Legeneralja a program a matrixot, csak ki kellene iratni… Ez mar tenyleg nem nagy keres… Ezert van a forum, nem?
2008-02-25-19:31 #2154698Jo. Akkor nem tudnal segiteni, ez mar tenyleg csak a vege. Legeneralja a program a matrixot, csak ki kellene iratni… Ez mar tenyleg nem nagy keres… Ezert van a forum, nem?
-
SzerzőBejegyzés
- Be kell jelentkezni a hozzászóláshoz.
legutóbbi hsz