/* fix mouse click offset errors when doing drags */
body {
margin: 0;
}
JavaScript
// a class encapsulting a math line and a actual line.
class Line {
constructor(p1,p2){
this.start = p1;
this.end = p2;
this.line3 = new THREE.Line3(p1, p2);
console.log(this.line3);
var lineGeo = new THREE.Geometry();
lineGeo.vertices.push(this.line3.start, this.line3.end);
var mat = new THREE.LineBasicMaterial({color:0xff0000});
this.mesh = new THREE.Line(lineGeo, mat);
var normal = this.getVectorNormal();
console.log(normal);
}
getVectorNormal(){
var normal = new THREE.Vector3();
normal.subVectors(this.end.clone(), this.start.clone());
var angle = THREE.Math.degToRad(90);
normal.applyAxisAngle(new THREE.Vector3(0,0,1), angle);
this.zeroOutNearZeroValues(normal);
return normal;
}
zeroOutNearZeroValues(vec){
var x = parseInt(vec.x.toFixed(3));
var y = parseInt(vec.y.toFixed(3));
var z = parseInt(vec.z.toFixed(3));
vec.x = x === 0 ? 0 : vec.x;
vec.y = y === 0 ? 0 : vec.y;
vec.z = z === 0 ? 0 : vec.z;
}
getDirection(){
var direction = new THREE.Vector3();
direction.subVectors(p2.clone(),p1.clone());
return direction;
}
/// a real math lin3, while you can move it, it's not easily resetable
// once moved, the new cordinates are its starting position
// to reset, you'll have to create a new properties like a position to offset from
setPosition(x=0,y=0,z=0){
this.line3.applyMatrix4(new THREE.Matrix4().makeTranslation(x,y,z));
this.mesh.geometry.verticesNeedUpdate = true;
}
}
class Utils {
static createArc(rad = 5, seg = 36, thetaStart = 0, thetaEnd = 360){
var radius = rad;
var segments = seg;
var pointGeo = new THREE.Geometry();
var thetaStart = THREE.Math.degToRad(thetaStart);
var thetaLength = THREE.Math.degToRad(thetaEnd);
// don't include center
// pointGeo.vertices.push(new THREE.Vector3(0,0,0));
for(var i=0; i<=segments; i++){
var...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.