Ⅰ 怎样在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;
}
第三个问题
没有明白你的‘点乘‘要干什么