static public PVector random2D(PVector target = null) { double angle = (_rand.NextDouble() * Math.PI * 2); if (target == null) { target = new PVector(Math.Cos(angle), Math.Sin(angle), 0); } else { target.set(Math.Cos(angle), Math.Sin(angle), 0); } return(target); }
public PVector cross(PVector v, PVector target) { double crossX = y * v.z - v.y * z; double crossY = z * v.x - v.z * x; double crossZ = x * v.y - v.x * y; if (target == null) { target = new PVector(crossX, crossY, crossZ); } else { target.set(crossX, crossY, crossZ); } return(target); }
static public PVector cross(PVector v1, PVector v2, PVector target) { double crossX = v1.y * v2.z - v2.y * v1.z; double crossY = v1.z * v2.x - v2.z * v1.x; double crossZ = v1.x * v2.y - v2.x * v1.y; if (target == null) { target = new PVector(crossX, crossY, crossZ); } else { target.set(crossX, crossY, crossZ); } return(target); }
public PVector normalize(PVector target) { if (target == null) { target = new PVector(); } double m = mag(); if (m > 0) { target.set(x / m, y / m, z / m); } else { target.set(x, y, z); } return(target); }
static public PVector random3D(PVector target = null) { double angle; double vz; angle = (_rand.NextDouble() * Math.PI * 2); vz = (_rand.NextDouble() * 2 - 1); double vx = (Math.Sqrt(1 - vz * vz) * Math.Cos(angle)); double vy = (Math.Sqrt(1 - vz * vz) * Math.Sin(angle)); if (target == null) { target = new PVector(vx, vy, vz); //target.normalize(); // Should be unnecessary } else { target.set(vx, vy, vz); } return(target); }
public PVector setMag(PVector target, double len) { target = normalize(target); target.mult(len); return(target); }
static public double dot(PVector v1, PVector v2) { return(v1.x * v2.x + v1.y * v2.y + v1.z * v2.z); }
public PVector cross(PVector v) { return(cross(v, null)); }
public double dot(PVector v) { return(x * v.x + y * v.y + z * v.z); }
static public PVector div(PVector v, double n) { return(div(v, n, null)); }
static public PVector mult(PVector v, double n) { return(mult(v, n, null)); }
static public PVector sub(PVector v1, PVector v2) { return(sub(v1, v2, null)); }
static public PVector add(PVector v1, PVector v2) { return(add(v1, v2, null)); }