Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
weshoke committed Apr 25, 2014
1 parent 6e3421a commit 88e39f6
Show file tree
Hide file tree
Showing 5 changed files with 423 additions and 21 deletions.
1 change: 1 addition & 0 deletions C2.js
Expand Up @@ -9,6 +9,7 @@ var C2 = versor.create({
{ name:"Par", bases:["e12", "e13", "e14", "e23", "e24", "e34"] },
{ name:"Dll", bases:["e1", "e2", "e4"], dual:true },
{ name:"Lin", bases:["e134", "e234", "e124"] },
{ name:"Cir", bases:["e123", "e234", "e124", "e134"] },
{ name:"Flp", bases:["e14", "e24", "e34"] },
{ name:"Drv", bases:["e14", "e24"] },
{ name:"Tnv", bases:["e13", "e23"] },
Expand Down
3 changes: 3 additions & 0 deletions C3.js
Expand Up @@ -118,6 +118,9 @@ C3.Fl = {
line: function(p1, p2) {
return p1.op(p2).op(C3.Inf);
},
plane: function(pos, drv) {
return C3.dual(pos.ip(drv));
},
dir: function(a) {
return a.isdual() ?
C3.e5(1).op(a) :
Expand Down
240 changes: 240 additions & 0 deletions examples/C2.Bst2.html
@@ -0,0 +1,240 @@
<!DOCTYPE html>
<html>
<head>
<title>C2 Geometric Algebra Test</title>
<script src="../versor.js"></script>
<script src="../C2.js"></script>
<script src="d3.v3.js" charset="utf-8"></script>
<link type="text/css" rel="stylesheet" href="style.css"/>
<style type="text/css">

svg {
background-color: rgba(0, 0, 0, 0.02);
}

path {
stroke: #000;
stroke-width: 0.01;
fill: none;
}


circle {
stroke: none;
fill: none;
stroke-opacity: .5;
stroke-width: 0.01;
}


line {
stroke: #000;
stroke-opacity: .5;
stroke-width: 0.01;
}

.generator {
stroke: #08f;
fill-opacity: 0.7;
stroke-width: 0.02;
}

.points {
fill: #000;
}

.transformedPoints {
fill: #F22;
}

.arrowline {
stroke-width: 0.02;
}

.arrowhead0 {
stroke: #000;
fill: #f08;
}

.arrowhead1 {
stroke: #000;
fill: #08f;
}

.generator {
stroke: #f33;
fill-opacity: 0.7;
}

.p1 {
fill: #f81;
}

.p2 {
fill: #17f;
}

</style>
<script>


document.addEventListener("DOMContentLoaded", function(evt) {
var Ro = C2.Ro;
var Fl = C2.Fl;
var Op = C2.Op;


var N=30;
var res=100;
var scale=100;
var w=600;
var h=600;
var pRadius = 2;
var svg = d3.select("#GA").append("svg:svg")
.attr("width", w)
.attr("height", h);

function canvasToWorld(p) {
return [
(p[0]-w/2)/scale,
(p[1]-h/2)/-scale,
];
}

var lines = [];
var Datum = [];
for(var i=0; i < N; ++i) {
var p1 = Ro.point(-2+4/(N-1)*i, -2);
var p2 = Ro.point(-2+4/(N-1)*i, 2);
var arr = [
[p1[0], p1[1]]

];

for(var k=0; k < 100; ++k) {
var p = Ro.point(-2+4/(N-1)*i, -2+4*k/100);
arr.push([p[0], p[1]]);
}
arr.push([p2[0], p2[1]]);
lines.push(arr);
Datum.push({
type:"LineString",
coordinates:arr
});
}
for(var i=0; i < N; ++i) {
var p1 = Ro.point(-2, -2+4/(N-1)*i);
var p2 = Ro.point(2, -2+4/(N-1)*i);
var arr = [
[p1[0], p1[1]]
];

for(var k=0; k < 100; ++k) {
var p = Ro.point(-2+4*k/100, -2+4/(N-1)*i);
arr.push([p[0], p[1]]);
}
arr.push([p2[0], p2[1]]);
lines.push(arr);
Datum.push({
type:"LineString",
coordinates:arr
});
}

var Data = {
type:"LineString",
//coordinates:lines
coordinates:[[0, 0], [1, 0]]
};
var Data2 = {
type:"LineString",
//coordinates:lines
coordinates:[[0, 1], [1, 1]]
};

var p1 = Ro.point(1, 1);
var p2 = Ro.point(1, 1.6);
var pp = p1.op(p2);
var bst = Op.bst(pp);

var g;
g = svg.append("svg:g")
.attr("transform", "translate("+(w/2)+", "+(h/2)+") scale("+scale+", "+(-scale)+")");

function dist(p1, p2) {
var dx = p1[0]-p2[0];
var dy = p1[1]-p2[1];
return Math.sqrt(dx*dx+dy*dy);
}

var path = d3.geo.path();
var transform = d3.geo.transform({
point: function(x, y) {
//console.log(x, y);
var p = Ro.point(x, y);
p = Ro.point.normalize(p.sp(bst));
this.stream.point(p[0], p[1]);
}
});
path.projection(transform);

var drag = (function() {
var circleStartPos = [0, 0];
var dragPoint = undefined;
var drag = d3.behavior.drag()
.on('dragstart', function(){
var pos = canvasToWorld(d3.mouse(this));
if(dist(pos, p1) < pRadius/scale) {
dragPoint = "p1";
}
else if(dist(pos, p2) < pRadius/scale) {
dragPoint = "p2";
}
else {
dragPoint = undefined;
}
})
.on('drag', function(){
if(dragPoint) {
var pos = canvasToWorld(d3.mouse(this));
if(dragPoint == "p1") p1 = Ro.point(pos[0], pos[1]);
else p2 = Ro.point(pos[0], pos[1]);
pp = p1.op(p2);
bst = Op.bst(pp);

var sel = g.selectAll(".generator").data([p1, p2]);
sel.attr("cx", function(d) { return d[0]; })
.attr("cy", function(d) { return d[1]; });

g.selectAll(".lines").data(Datum)
.attr("d", path);
}
});
return drag;
})();

svg.call(drag);




g.selectAll(".lines").data(Datum)
.enter()
.append("path")
.attr("class", "lines")
.attr("d", path);

g.selectAll(".generator").data([p1, p2])
.enter().append("svg:circle")
.attr("class", function(d, i) { return "generator p"+(i+1); })
.attr("cx", function(d) { return d[0]; })
.attr("cy", function(d) { return d[1]; })
.attr("r", function(d) { return pRadius/scale; });
});
</script>
</head>
<body>
<h3>C2 Geometric Algebra Test</h3>
<div id="GA"></div>
</body>
</html>

0 comments on commit 88e39f6

Please sign in to comment.