/** * Catlair JS Copyright (C) 2019 a@itserv.ru * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Vector coordinate work * http://catlair.net/?template=clVector.js * * still@itserv.ru * * Plans: * Сделать надо нормальный генератор RND и на него переделать метод RND для получения случайной точки. */ class clVector { x=0; y=0; z=0; Set(AX, AY, AZ) { if (AX) {this.x=AX} else {this.x=0}; if (AY) {this.y=AY} else {this.y=0}; if (AZ) {this.z=AZ} else {this.z=0}; return this; } Get() { return new clVector(this.x, this.y, this.z); } Zero() { this.x=0; this.y=0; this.z=0; return this; } Load(AVector) { this.x=AVector.x; this.y=AVector.y; this.z=AVector.z; this.v=AVector.v; return this; } Mov(AVector) { AVector.x=this.x; AVector.y=this.y; AVector.z=this.z; return AVector; } Not() { this.x=-this.x; this.y=-this.y; this.z=-this.z; return this; } GetNot() { return new clVector(-this.x, -this.y, -this.z); } Equal(AVector) { return (Math.abs(this.x-AVector.x) < clEpsilon && Math.abs(this.y-AVector.y) < clEpsilon && Math.abs(this.z-AVector.z) < clEpsilon); } Epsilon() { return (Math.abs(this.x) < clEpsilon && Math.abs(this.y) < clEpsilon && Math.abs(this.z) < clEpsilon); } Add(AVector) { this.x=this.x+AVector.x; this.y=this.y+AVector.y; this.z=this.z+AVector.z; return this; } GetAdd(AVector) { return new clVector(this.x+AVector.x, this.y+AVector.y, this.z+AVector.z); } Sub(AVector) { this.x=this.x-AVector.x; this.y=this.y-AVector.y; this.z=this.z-AVector.z; return this; } GetSub(AVector) { return new clVector(this.x-AVector.x, this.y-AVector.y, this.z-AVector.z); } Scal(AScale) { this.x=this.x*AScale; this.y=this.y*AScale; this.z=this.z*AScale; return this; } GetScal(AScale) { return new clVector(this.x*AScale, this.y*AScale, this.z*AScale); } Mul(AVector) { this.x=this.x*AVector.x; this.y=this.y*AVector.y; this.z=this.z*AVector.z; return this; } GetMul(AVector) { return new clVector(this.x*AVector.x, this.y*AVector.y, this.z*AVector.z); } String() { return 'x:'+clFloatToStr(this.x)+' y:'+clFloatToStr(this.y)+' z:'+clFloatToStr(this.z); } }; function clEpsilonControl(A) { if (Math.abs(A) < clEpsilon) {return 0} else {return A}; } function clVectorDefine(AX, AY, AZ) { var Result = new clVector(); Result.Set(AX,AY,AZ); return Result; } var clEpsilon=0.00000001; /* Small value */ var clEpsilonLength=8; var clXVector = clVectorDefine(1,0,0); var clYVector = clVectorDefine(0,1,0); var clZVector = clVectorDefine(0,0,1); var clPI2 = Math.PI*2; var clPI1 = Math.PI; var clPI05 = Math.PI*0.5;