Ⅰ 怎樣在java3d裡面實現 自動旋轉效果
查看點就是個3維向量
計算移動的時候把方向也一並計算就好了
JAVA 3D不熟悉 以前搞Direct3D的 也忘光了
Ⅱ 編寫一個函數,計算3D向量的模
#include <iostream>
#include <cmath>
using namespace std;
struct Vector3D
{
float x;
float y;
float z;
Vector3D()
:x(0), y(0), z(0)
{ }
Vector3D(float x, float y, float z)
{
this->埋乎x = x;
this->y = y;
this->z = z;
}
Vector3D operator-(Vector3D &v)
{
Vector3D r;
r.x = this->x - v.x;
r.y = this->y - v.y;
r.z = this->z - v.z;
return r;
}
float length() const
{
return sqrt(x * x + y * y + z * z);
}
void output() const
{
cout << "(" <侍棗< x << "," << y << "," << z <<"彎談悉)" << endl;;
}
};
int main(void)
{
Vector3D v1(3, 2, 1);
Vector3D v2(1, 1, 1);
Vector3D v = v1 - v2;
v1.output();
v2.output();
v.output();
cout << v.length() << endl;
return 0;
}
Ⅲ java向量
publicclassTest7{
//cos夾角=a向量點乘b向量/(a向量的模*b向量的模),這里沒有考版慮經度問題。
publicstaticvoidmain(String[]args){
權intx1=3,y1=4,z1=5;
intx2=6,y2=8,z2=10;
doublediancheng=x1*x2+y1*y2+z1*z2;
doubleaa=Math.sqrt(Math.pow(x1,2)+Math.pow(y1,2)+Math.pow(z1,2));
doublebb=Math.sqrt(Math.pow(x2,2)+Math.pow(y2,2)+Math.pow(z2,2));
doublecos=Math.round(diancheng/(aa*bb));
System.out.println("夾角為:"+Math.acos(cos));
}
}
Ⅳ java中向量計算用array
第一個問題,for那裡的最後的那個; 去掉就可以了
for(int i = 0; i<v1.length; i++)
第二個問題版
public double getSum(double[] v1, double length){
權for(int i = 0; i < v1.length; i++){
length = length + v1[i] * v1[i];
}
return length;
}
第三個問題
沒有明白你的『點乘『要干什麼