-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbivector2.html
More file actions
132 lines (104 loc) · 3.86 KB
/
Copy pathbivector2.html
File metadata and controls
132 lines (104 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
<head>
<title>BiVector in 2D</title>
<script language="JavaScript" src="basiccontext.js"></script>
<script>
var SCL = 1
var base = timesSc( vec2(125,125), SCL );
var vecA = vec2(1,0);
var vecB = vec2(0,-1);
var len = 50 * SCL;
function project( v )
{
return {
x: base.x + v.x * len,
y: base.y + v.y * len };
}
function area(v0,v1)
{
return v0.x*v1.y - v0.y*v1.x;
}
var selectedThing = 0;
var render = function()
{
if ( !isActive ) return;
if ( !context ) return;
if (mouseIsDown)
{
if ( selectedThing == 0 )
{
if ( around( mousePos, project(vecA), 8 ) )
selectedThing = 1;
else if ( around( mousePos, project(vecB), 8 ) )
selectedThing = 2;
}
if ( selectedThing == 1 )
vecA = normalize( minus(mousePos,base) );
if ( selectedThing == 2 )
vecB = normalize( minus(mousePos,base) );
}
else
selectedThing = 0;
context.clearRect(0, 0, canvas.width, canvas.height);
areaBv = -area(vecA,vecB);
var colorBv = 'rgba(0,102,255,0.8)';
if ( areaBv < 0 )
colorBv = 'rgba(0,200,102,0.8)';
DrawLine( plus(base,vec2(0,-150*SCL)), plus(base,vec2(0,(150+50)*SCL)), 'gray', 1 );
DrawLine( base, plus(base,vec2(0,-len)), 'gray', 5 );
WriteText( 'x', plus(base,vec2(90*SCL,-3*SCL)), '15pt '+DefFont, 'gray' );
DrawLine( plus(base,vec2(-150*SCL,0)), plus(base,vec2(150*SCL,0)), 'gray', 1 );
DrawLine( base, plus(base,vec2(len,0)), 'gray', 5 );
WriteText( 'y', plus(base,vec2(3*SCL,-90*SCL)), '15pt '+DefFont, 'gray' );
DrawDisc( base, 6, 'black' );
DrawQuad( base, project(vecA), project(plus(vecA,vecB)), project(vecB), colorBv );
DrawLine( base, project(vecA), 'black', 3 );
DrawLine( base, project(vecB), 'black', 3 );
var colorA = '#ff0000'; if ( selectedThing == 1 ) colorA = '#fff';
DrawDisc( project(vecA), 4, colorA );
DrawCircle( project(vecA), 8, colorA, 2 );
var colorB = '#ff0000'; if ( selectedThing == 2 ) colorB = '#fff';
DrawDisc( project(vecB), 4, colorB );
DrawCircle( project(vecB), 8, colorB, 2 );
WriteText( 'a', plus(project(vecA), vec2(0,-10)), '15pt '+DefFont, 'black' )
WriteText( 'b', plus(project(vecB), vec2(0,-10)), '15pt '+DefFont, 'black' )
WriteText( "a"+"\u2227"+"b = " + areaBv.toFixed(3) + " x"+"\u2227"+"y", timesSc(vec2(130,280-10),SCL), (11*SCL) + 'pt '+DefFont, colorBv )
DrawArcSimple( vec3(vecA.x,vecA.y,0), vec3(vecB.x,vecB.y,0), 'white', 1, null, 'white', 1-0.2, 0.2 )
var basSinY = 250*SCL;
var basH = 40*SCL;
DrawLine( vec2(0,basSinY), vec2(250*SCL,basSinY), 'gray', 1 );
DrawLine( vec2(0,basSinY-basH-20), vec2(250*SCL,basSinY-basH-20), 'gray', 5 );
context.beginPath();
context.lineWidth = 1;
context.strokeStyle = 'yellow';
for ( var i = 0; i <= 50; ++i )
{
var vx = i/50.0 * 2 * Math.PI;
p = vec2( vx * basH, Math.sin( vx ) * basH + basSinY );
if (i==0) context.moveTo( p.x, p.y ); else context.lineTo( p.x, p.y );
}
context.stroke();
var dp = dot( vecA, vecB )
var as = Math.asin( areaBv );
var vv = as;
if ( areaBv > 0 && dp > 0 )
vv = (Math.PI - as);
else if ( areaBv < 0 && dp > 0 )
vv = -as - Math.PI;
vv = vv + Math.PI;
DrawLine( vec2(vv*basH,0+basSinY), vec2(vv*basH,areaBv*-basH+basSinY), colorBv, 4 );
}
window.setInterval(render, 16);
</script>
<style>
body { background-color: #ccc; color: white; font-family: arial; font-size: 15px; margin: 0; padding: 0; }
canvas { margin: 0; padding: 0; border: 0px solid black;
/* position: absolute;top: 50%;left: 50%; margin: -300px 0 0 -250px; */
}
</style>
</head>
<body onload="OnLoad()">
<canvas id="myCanvas" width="250" height="300"></canvas>
</div>
</body>
</html>