Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Runtime(
- )
- {
- console.log("Running");
- }
- function initViewPort(
- width,
- height
- )
- {
- var viewport = $("#viewport");
- for (var i = 0; i < 500; i++) {
- viewport.append("<div class='pixel'></div>");
- }
- }
- initViewPort(100,200)
- // Geometry
- function GetSquareArea(length)
- {
- return length * length;
- }
- function GetRectangleArea(
- width,
- height
- )
- {
- return width * height;
- }
- function GetRectTriangleArea(
- width,
- height
- )
- {
- return width * height / 2;
- }
- // ENnd of Geometry
- function PopulateLimitDataSet(
- limit
- )
- {
- var limitsData = [];
- var upScaleLimitTracker = limit;
- var downScaleLimitTracker = limit;
- // Generate the down limits sets
- for (var i = 0; i < 10; i++) {
- upScaleLimitTracker += 0.0001;
- limitsData.push(upScaleLimitTracker);
- }
- // Generate the down limits sets
- for (var i = 0; i < 10; i++) {
- downScaleLimitTracker -= 0.0001;
- limitsData.push(downScaleLimitTracker);
- }
- return limitsData;
- }
- function cartesian2Polar(x,
- y)
- {
- distance = Math.sqrt(x*x + y*y)
- radians = Math.atan2(y,x) //This takes y first
- polarCoor = { distance:distance, radians:radians }
- return polarCoor
- }
- // Returns either or not the two point are rationnal
- function IsRationnal(
- PointA,
- PointB
- )
- {
- // From proof of: p/(−q) = (−p)/q, (−p)/(−q) = p/q.
- var p = PointA;
- var q = PointB;
- // Define two items to compare proof A
- var ProofANumber1 = p / ToNegativeNumber(q);
- var ProofANumber2 = ToNegativeNumber(p) / q;
- // Define two items to compare proof B
- var ProofBNumber1 = ToNegativeNumber(p)/ToNegativeNumber(q);
- var ProofBNumber2 = p/q;
- if (ProofANumber1 == ProofANumber2
- &&
- ProofBNumber1 == ProofBNumber2) {
- return true;
- } else {
- return false;
- }
- }
- // Is commutative
- function IsValidLine3(
- a,
- b,
- c
- ){
- if( a + b == b + a &&
- a + (b + c) == (a + b) + c &&
- a * b == b * a &&
- a * (b + c) == (a * b) * c
- ) {
- return true;
- } else
- {
- return false;
- }
- }
- function InitVector3(
- x,
- y,
- z
- )
- {
- var Vector3 = {};
- Vector3.x = x;
- Vector3.y = y;
- Vector3.z = z;
- return Vector3;
- }
- function InitVector3AtOrigin(
- )
- {
- var Vector3 = {};
- Vector3.x = 0;
- Vector3.y = 0;
- Vector3.z = 0;
- return Vector3;
- }
- function InitHomogeneousVectorAtOrigin()
- {
- var HomogeneousPoint = {};
- HomogeneousPoint.x = 0;
- HomogeneousPoint.y = 0;
- HomogeneousPoint.z = 0;
- HomogeneousPoint.w = 0;
- return HomogeneousPoint;
- }
- function InitHomogeneousVectorAtCoordinate(
- x,
- y,
- z,
- w
- )
- {
- var HomogeneousPoint = {};
- HomogeneousPoint.x = x;
- HomogeneousPoint.y = y;
- HomogeneousPoint.z = z;
- HomogeneousPoint.w = w;
- return HomogeneousPoint;
- }
- //||V||=x+V.y∗V.y+V.z∗V.z−−−−−−−−−−−−−−−−−−−−−−−−−−−−√
- function FindVectorLength(
- Vector
- )
- {
- var length = Math.sqrt(Vector.x * Vector.x + Vector.x * Vector.y + Vector.y * Vector.z )
- return length;
- }
- function NormalizeVector(
- Vector,
- NormalVal
- )
- {
- var length = Math.sqrt(Vector.x * Vector.x + Vector.x * Vector.y + Vector.y * Vector.z )
- var inverseLength = NormalVal / length;
- x *= inverseLength
- y *= inverseLength
- z *= inverseLength
- return Vector;
- }
- function DotProductVector(
- VectorA,
- VectorB
- )
- {
- var NewVector = {};
- NewVector.x = (VectorA.x * VectorB.x);
- NewVector.y = (VectorA.y * VectorB.y);
- NewVector.z = (VectorA.z * VectorB.z);
- // var DotProduct = + (VectorA.y * VectorB.y) + (VectorA.z * VectorB.z);
- return NewVector;
- }
- function CrossProduct(
- VectorA,
- VectorB
- )
- {
- /*
- CX =AY∗BZ−AZ∗BY
- CY =AZ∗BX−AX∗BZ
- CZ =AX∗BY−AY∗BX
- */
- /*
- */
- var NewVector = {};
- NewVector.x = (VectorA.y * VectorB.z) - (VectorA.z * VectorB.y);
- NewVector.y = (VectorA.z * VectorB.x) - (VectorA.x * VectorB.z);
- NewVector.z = (VectorA.x * VectorB.y) - (VectorA.y * VectorB.x);;
- // var DotProduct = + (VectorA.y * VectorB.y) + (VectorA.z * VectorB.z);
- return NewVector;
- }
- // Matrices
- function InitMatrix(
- sizeCol,
- sizeRow
- )
- {
- const matrix = new Array(sizeRow).fill(0).map(() => new Array(sizeRow).fill(0));
- return matrix;
- }
- function MultiplyMatrices4(
- MatriceA,
- MatriceB
- )
- {
- var MultMatrix = new Array(4).fill(0).map(() => new Array(4).fill(0));
- for (var i = 0; i < 4; ++i) {
- for (var j = 0; j < 4; ++j) {
- MultMatrix[i][j] =
- MatriceA[i][0] * MatriceB[0][j] +
- MatriceA[i][1] * MatriceB[1][j] +
- MatriceA[i][2] * MatriceB[2][j] +
- MatriceA[i][3] * MatriceB[3][j];
- }
- }
- return MultMatrix;
- }
- function GenerateRandomDataMatrix(
- sizeCol,
- sizeRow,
- min,
- max
- )
- {
- var RandomDataMatrix = new Array(sizeCol).fill(0).map(() => new Array(sizeCol).fill(0));
- for (var i = 0; i < sizeCol; ++i) {
- for (var j = 0; j < sizeRow; ++j) {
- RandomDataMatrix[i][j] = Math.floor(Math.random() * (+max - +min)) + +min;
- }
- }
- return RandomDataMatrix;
- }
- var newRandomData = GenerateRandomDataMatrix(10,15, 10, 2500);
- console.log(newRandomData);
- var MatricesTest = InitMatrix(5,5);
- console.log(MatricesTest);
- var v = InitVector3(3,4,5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement