Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
423 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.