forked from enkimute/ganja.js
-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
144 additions
and
9 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
File renamed without changes
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,51 @@ | ||
<HEAD> | ||
<SCRIPT SRC="../ganja.js"></SCRIPT> | ||
</HEAD> | ||
<BODY><SCRIPT> | ||
// Create a Clifford Algebra with 3,1 metric for 2D CGA. | ||
Algebra(3,1,()=>{ | ||
|
||
// The conformal model adds in more element types. (circles, point-pairs) | ||
// We no longer work in a dual space. (so ^ = join and & = meet) | ||
// Vectors are points, Bivectors are point pairs, Trivectors are lines/circles | ||
|
||
// We don't work directly in the e3/e4 basis, but instead rotate it so we have | ||
// two null vectors to work with (called origin and infinite) | ||
var ei = 1e4-1e3, // e-infinite | ||
eo = 0.5*(1e4+1e3); // e-origin | ||
|
||
// Define points, lines, circles using the null basis. | ||
var point = (x,y)=>eo + x*1e1 + y*1e2 + 0.5*(x*x+y*y)*ei, | ||
line = (a,b,c)=>!(a*1e1 + b*1e2 + c*ei), | ||
circle = (x,y,r)=>!(point(x,y) - r**2/2*ei); | ||
|
||
// Distances and Angles. | ||
var dist=(x,y)=>(2*(x<<y).Length)**0.5, | ||
angle=(x,y)=>Math.acos(!x.Normalized<<!y.Normalized); | ||
|
||
// Define three points | ||
var p1 = point(-0.5, -0.5), | ||
p2 = point( 1, -0.5), | ||
p3 = point( 0, 1.5); | ||
|
||
// Define two circles, one by wedging 3 points, one directly. | ||
var C = ()=>p1^p2^p3, // a function so it updates live. | ||
D = circle(1,-1,0.9); | ||
|
||
// Define two lines, one directly, one by wedging two points and infinity. | ||
var X=line(0,1,0), Y=()=>p2^p3^ei; | ||
|
||
// Create point pairs by intersecting circle(s) and a line(s). | ||
var pp1=()=>X&C, pp2=()=>C&D, pp3=()=>Y&D; | ||
|
||
// Graph these items. | ||
document.body.appendChild(this.graph([ | ||
"2D CGA - drag p1,p2,p3","", // title | ||
0xFF8888, C, "C", D, "D", // circles | ||
0x44AA44, X, "X", Y, "Y", // lines | ||
0x4444FF, pp1, "pp1", pp2, "pp2", pp3, "pp3", // point pairs | ||
0x666666, p1, "p1", p2, "p2", p3, "p3", // points | ||
],{conformal:true})); // conformal flag! | ||
|
||
}); | ||
</SCRIPT></BODY> |
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,48 @@ | ||
<HEAD> | ||
<SCRIPT SRC="../ganja.js"></SCRIPT> | ||
</HEAD> | ||
<BODY><SCRIPT> | ||
// Create a Clifford Algebra with 3,1 metric for 2D CGA. | ||
Algebra(3,1,()=>{ | ||
|
||
// Two null vectors to work with (called origin and infinite) | ||
var ei = 1e4-1e3, // e-infinite | ||
eo = 0.5*(1e4+1e3); // e-origin | ||
|
||
// Define points, lines, circles using the null basis. | ||
var point = (x,y)=>eo + x*1e1 + y*1e2 + 0.5*(x*x+y*y)*ei, | ||
line = (a,b,c)=>!(a*1e1 + b*1e2 + c*ei), | ||
circle = (x,y,r)=>!(point(x,y) - r**2/2*ei); | ||
|
||
// Some identities | ||
var line_through_P_parallel_with_X = (P,X)=>X<<(P^ei)*(P^ei), | ||
project_point_on_circle = (P,C)=>C<<(P^ei)*C, | ||
project_point_on_line = (P,L)=>L.Normalized<<P*L.Normalized, | ||
position = (X)=>{ X=X/(X^ei); return X/(-ei<<X); }, | ||
radius = (X)=>Math.abs(((X<<X).s/((X^ei)**2).s))**.5, | ||
attitude = (X)=>(X^ei<<(ei^eo)).Normalized, | ||
split = (pp)=>position(pp)-radius(pp)*attitude(pp); | ||
|
||
// Define some elements. | ||
var p1 = point(-0.7,0.4), p2 = point(1,-0.5), p3 = point(0,1.5), | ||
D = circle(1,-1,0.7), | ||
X = line(0,1,0), Y=()=>p2^p3^ei; | ||
|
||
// Graph | ||
document.body.appendChild(this.graph([ | ||
"2D CGA - drag p1,p2,p3","", // title | ||
0xFF8888, D, // circle | ||
()=>position(D), ()=>"D "+(radius(D).toFixed(2)), // Center,Radius | ||
0x44AA44, X, "X", Y, "Y", // lines | ||
0x4444FF, | ||
()=>line_through_P_parallel_with_X(p1,Y),"p1 // Y", // parallel to line | ||
()=>line_through_P_parallel_with_X(p1,D),"p1 // D", // parallel to circle | ||
0xFF44FF, | ||
()=>split(project_point_on_circle(p1,D)),"p1 on D", // project on circle | ||
()=>project_point_on_line(p1,X), "p1 on X", // project on line | ||
()=>project_point_on_line(p1,Y), "p1 on Y", // project on line | ||
0x444444,p1,"p1",p2,"p2",p3,"p3", // render the points | ||
],{conformal:true})); // conformal flag! | ||
|
||
}); | ||
</SCRIPT></BODY> |
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