Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Work-in-progress version of Doppler-shifted light flashes for issue #120

.
  • Loading branch information...
commit e7ef7239284762a917bcb4c8e39c2910805f23c0 1 parent 5307fd9
@capnrefsmmat capnrefsmmat authored
View
4 relativity/demos/exam_1.json
@@ -28,7 +28,7 @@
"p": [-4, 0, 0], "m": 1,
"shape": {"type": "man", "params": [3, 7]},
"options": {"showVelocity": false}},
- {"object": "photon", "x": [-160, 10, 0, 170],
+ {"object": "lightFlash", "x": [-160, 10, 0, 170],
"v": [-1, 0, 0], "options": {"showCircle": true}},
{"object": "photon", "x": [-240, 10, 0, 170],
"v": [1, 0, 0], "options": {"showCircle": true}},
@@ -67,7 +67,7 @@
"x": [0, -5, 0], "p": [-4, 0, 0], "m": 1,
"shape": {"type": "man", "params": [3, 7]},
"options": {"showVelocity": false}},
- {"object": "photon", "x": [-160, 10, 0, 170],
+ {"object": "lightFlash", "x": [-160, 10, 0, 170],
"v": [-1, 0, 0], "options": {"showCircle": true}},
{"object": "photon", "x": [-240, 10, 0, 170],
"v": [1, 0, 0], "options": {"showCircle": true}}
View
40 relativity/js/extendedObject.js
@@ -1,5 +1,4 @@
-// Time is component 3
-//lNB: Shape is four dimensional,
+// Time is component 3. NB: Shape is four dimensional.
"use strict";
@@ -37,15 +36,13 @@ function extendedObject(X, P, label, options, shape) {
this.created = false;
}
+ // Objects are modeled as blackbodies, so their color is determined by
+ // temperature.
this.temp = (options.temperature) ? options.temperature : 5600;
this.stillColor = tempToColor(this.temp);
this.label = label;
- if (options.interestingPts) {
- this.interestingPts = options.interestingPts;
- }
-
if (options.endPt) this.COM.endPt = quat4.create(options.endPt);
if (options.initialPt) this.COM.initialPt = options.initialPt;
if (options.initialTau) {
@@ -78,7 +75,8 @@ function extendedObject(X, P, label, options, shape) {
this.shapePoints[this.boundingIdx[2 * j + 1]][j]) {
this.boundingIdx[2 * j + 1] = i;
}
- if (this.shapePoints[i][j] > this.shapePoints[this.boundingIdx[2 * j]][j]) {
+ if (this.shapePoints[i][j] >
+ this.shapePoints[this.boundingIdx[2 * j]][j]) {
this.boundingIdx[2 *j] = i;
}
}
@@ -117,7 +115,7 @@ extendedObject.prototype = {
// If not, just compute the new locations of the bounding box vertices.
// Doing things this way means it takes one frame after the object is
// in view before we start drawing it, but saves redundant computation
- // or further if statements if it is visible.
+ // or further `if` statements if it is visible.
else {
for (var j = 0; j < (this.boundingIdx.length); j++) {
var i = this.boundingIdx[j];
@@ -128,8 +126,8 @@ extendedObject.prototype = {
}
}
- // See if we need the light delayed points. Note that calPastPoints also
- // takes care of is/was interesting.
+ // See if we need the light delayed points. Note that calcPastPoints
+ // also takes care of is/was interesting.
if (scene.options.alwaysShowVisualPos || scene.options.interactions ||
(!scene.options.neverShowVisualPos && this.options.showVisualPos)) {
this.calcPastPoints();
@@ -141,8 +139,8 @@ extendedObject.prototype = {
/**
* Find the bounding boxes from the updated points and the indices.
- * The bounding box does not always contain the whole object, but it comes close.
- * Best case is a circle/sphere (always contained), worst case is a
+ * The bounding box does not always contain the whole object, but it comes
+ * close. Best case is a circle/sphere (always contained), worst case is a
* slightly oblate square/cube.
*/
findBB: function(pointsArr, BB) {
@@ -172,7 +170,7 @@ extendedObject.prototype = {
/**
* Map all the vectors involved in this object onto a new frame.
* translation1 is a translation in the present frame.
- * rotation is lorentz transform defined by a matrix including boost or rotation.
+ * rotation is Lorentz transform matrix including boost or rotation.
* translation2 is a translation in the new frame.
*/
changeFrame: function(translation1, rotation, translation2) {
@@ -208,6 +206,8 @@ extendedObject.prototype = {
}
}
if (this.options.showMinkowski) this.drawXT(scene);
+
+ // In debug mode, draw the future bounding box.
if (scene.debug) {
for (var i = 0; i < this.boundingBox.length; i++) {
scene.g.beginPath();
@@ -223,9 +223,9 @@ extendedObject.prototype = {
/**
* NB: these methods assume a model of Born rigidity.
- * Objects are assumed to have an infinite speed of sound.
- * This can lead to non-local effects under high acceleration.
- * Future cone is calculated in here for now as there is a lot of redundant calculation.
+ * Objects are assumed to have an infinite speed of sound. This can lead to
+ * non-local effects under high acceleration. Future cone is calculated in
+ * here for now as there is a lot of redundant calculation.
*/
calcPastPoints: function() {
var gamma = this.COM.V[3] / c;
@@ -239,8 +239,8 @@ extendedObject.prototype = {
var v = quat4.scale(this.COM.V, 1 / gamma, tempQuat4);
- // If it's interesting, solve for the intersection of this world-line and the
- // light cone for every point.
+ // If it's interesting, solve for the intersection of this world-line
+ // and the light cone for every point.
if (this.wI3d || this.wI2d) {
var j = 0;
for (var i = 0; i < (this.shapePoints.length); i++) {
@@ -318,13 +318,13 @@ extendedObject.prototype = {
scene.g.stroke();
// If we're drawing text, find the appropriate position and draw some text.
- if(scene.curOptions.showText) {
+ if (scene.curOptions.showText) {
var i = 1;
var textX = (this.boundingBox[0] + this.boundingBox[1]) /
(2 * scene.zoom) + scene.origin[0] - 10;
var textY = -this.boundingBox[3] / scene.zoom + scene.origin[1];
if (this.options.showVelocity) {
- scene.g.fillText("v = " + (Math.round(1000 * Math.sqrt(1-Math.min(1/Math.pow(this.COM.V[3] / c, 2), 1))) / 1000) + "c",
+ scene.g.fillText("v = " + (Math.round(1000 * Math.sqrt(1 - Math.min(1 / Math.pow(this.COM.V[3] / c, 2), 1))) / 1000) + "c",
textX, textY - 10 * i);
i++;
}
View
44 relativity/js/photon.js
@@ -48,9 +48,11 @@ function photon(X, V, label, options) {
photon.prototype.update = function(timeStep) {
// Bring it to now.
quat4.scale(this.V, timeStep/this.V[3], this.displace);
- // No c needed here, the speed of light dependance comes from timeStep being in metres.
+ // No c needed here, the speed of light dependence comes from timeStep
+ // being in metres.
quat4.add(this.X0, this.displace);
- // Move it back in time one timeStep (so we go forward in time and wind up at now)
+ // Move it back in time one timeStep (so we go forward in time and wind up
+ // at now)
this.X0[3] = this.X0[3] - timeStep;
this.initialPt[3] = this.initialPt[3] - timeStep;
// If there's an end point, move that back in time, too.
@@ -226,25 +228,25 @@ photon.prototype.drawXT = function(scene) {
};
photon.prototype.drawNow = function(scene) {
- if (this.initialPt[3] < 0) {
- // As you can't see or reflect light off of a photon, doppler shift in this context represents something a bit different.
- // In the unphysical view the photon is shown with the wavelength corresponding to its momentum in the current frame.
- // V is proportional to momentum in units of per meter for now.
- if (scene.options.alwaysDoppler ||
- (this.options.showDoppler && !scene.options.neverDoppler)) {
- scene.g.fillStyle = wavelengthToColor(1/this.V[3]);
- } else {
- scene.g.fillStyle = wavelengthToColor(this.wavelength);
- }
- scene.g.beginPath();
- scene.g.arc(this.X0[0] / scene.zoom + scene.origin[0],
- -this.X0[1] / scene.zoom + scene.origin[1],
- 2, 0, twopi, true);
- scene.g.fill();
- if (this.label !== "") {
- scene.g.fillText(this.label, this.X0[0] / scene.zoom + scene.origin[0],
- -this.X0[1] / scene.zoom + scene.origin[1] + 10);
- }
+ // As you can't see or reflect light off of a photon, doppler shift in this
+ // context represents something a bit different. In the unphysical view the
+ // photon is shown with the wavelength corresponding to its momentum in the
+ // current frame. V is proportional to momentum in units of per meter for
+ // now.
+ if (scene.options.alwaysDoppler ||
+ (this.options.showDoppler && !scene.options.neverDoppler)) {
+ scene.g.fillStyle = wavelengthToColor(1/this.V[3]);
+ } else {
+ scene.g.fillStyle = wavelengthToColor(this.wavelength);
+ }
+ scene.g.beginPath();
+ scene.g.arc(this.X0[0] / scene.zoom + scene.origin[0],
+ -this.X0[1] / scene.zoom + scene.origin[1],
+ 2, 0, twopi, true);
+ scene.g.fill();
+ if (this.label !== "") {
+ scene.g.fillText(this.label, this.X0[0] / scene.zoom + scene.origin[0],
+ -this.X0[1] / scene.zoom + scene.origin[1] + 10);
}
};
View
4 relativity/js/scene.js
@@ -201,6 +201,10 @@ Scene.prototype = {
case "photon":
thingy = new photon(obj.x, obj.v, obj.label, obj.options);
break;
+
+ case "lightFlash":
+ thingy = new lightFlash(obj.x, obj.v, obj.label, obj.options);
+ break;
case "fourEvent":
thingy = new fourEvent(obj.x, obj.options, this);
View
1  relativity/relativity.html
@@ -15,6 +15,7 @@
<script type="text/javascript" src="js/glMatrix-extensions.js"></script>
<script type="text/javascript" src="js/inertialObject.js"></script>
<script type="text/javascript" src="js/photon.js"></script>
+ <script type="text/javascript" src="js/lightFlash.js"></script>
<script type="text/javascript" src="js/relLibs.js"></script>
<script type="text/javascript" src="js/fourEvent.js"></script>
<script type="text/javascript" src="js/colors.js"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.