Hozzászólások
-
SzerzőBejegyzés
-
kosz kisbetu a mar megszokott, most is epito megjegyzesedet…
Jo. 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?
Jo. 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?
Nos? Tudna valaki segiteni?
Nos? Tudna valaki segiteni?
Asszem 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;
}Asszem 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;
}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]
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]
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;
} -
SzerzőBejegyzés
legutóbbi hsz