Schroedingers-Hat / jsphys

Libraries for physics simulation on javascript canvas
GNU Affero General Public License v3.0
11 stars 1 forks source link

"Rulers" between arbitrary objects #11

Open capnrefsmmat opened 13 years ago

capnrefsmmat commented 13 years ago

If we want to facilitate demonstrations of length contraction between various reference frames, we should provide a way for users to see the "distance" between two objects as measured in their current reference frame.

A "ruler" could be defined to span between any two objects, and would consist of a connecting line labeled with a length. (It could have tick marks like a ruler if you want to be fancy.)

Example use:

  1. Place two stationary objects a fixed distance apart and have a ruler span between them.
  2. Have another object move past them at a relativistic velocity. Note the distance between them.
  3. Restart, but this time in the moving object's reference frame. Note the length contraction. Repeat at various velocities.

For canned demos to embed in webpages or to use in classes, this could be very useful. "First I want you to calculate what will happen using the Lorentz factor, then we can see what really happens to the length..."

Schroedingers-Hat commented 13 years ago

Sounds good. Do remember that we (at present, doppler and light delay will add a bit of a load) have a budget of 1000s (my eee started really chugging at 40,000 if it was only updating) of (inertial point-like) objects to work with, especially if they're not all drawn, we could even render a 2d 200x200 pixel extended image/object with the engine as it is if we store the values in an array and display them all at once. I imagine that (for inertial objects at least) we can safely assume less than a 10x slow down.

Perhaps our inertial object shouldn't have a draw function, instead make some class (please excuse/correct me if I get the jargon wrong) which inherits all the physics and use this for drawing our blobs (let's call them stars seeing as they're hot and huge and far apart). Then we can have a lighter weight class which just returns positions. It can also hold a piece of information like 'i'm 1 metre along the ruler' use an array of these for composite objects and draw and number a single path.

I'm still trying to wrap my head around a way of handling rigid objects efficiently, will keep you posted.

Another thought I had was some relativistic string. Tie two objects together with very weak string and it will tell you when it breaks.

Another thing that may be more along the lines of what you mean is some kind of measureDistanceTo method. Something along the lines of creating a temporary frame (or copy of the two objects of interest), translate to one, boost to its frame, calculate the distance, then discard everything else. It'd be a few vector operations, fairly quick. I will ponder if there is a quicker method.

Schroedingers-Hat commented 13 years ago

Started writing measure, it's looking very much like the method I'll be using to make objects react to each other. I got as far as far as a displacement vector pointing to the object to be measured (in the wrong time) and a relative velocity. I left some comments outlining what needs to be done. I encourage you to finish it as this will be a good way to grow accustomed to how I've been doing things. The logic from there on follows updateX0 fairly closely., with displacement and measureV rather than X0 and V. Maybe you can do something clever to avoid large amounts of copy-pasta? I'm a bit lost when it comes to knowing exactly when javascript passes a reference and when it copies.

Additionally if you can make something that follows the logic of calcPast() using those same vectors we will have everything in place we need to do (1 way) interactions, such as a test particle in a pre-determined charge distribution.

Schroedingers-Hat commented 13 years ago

I just realised this isn't exactly what we wanted for what you meant. I was thinking mobile or stationary rulers for mobile or stationary things. It's still incredibly useful and parts of it are required for a number of things (basically all interactions). But all we really need for what Capn wanted is the current frame's (stationary) ruler measuring moving things. This is as simple as Math.sqrt(spaceDot(quat4.subtract(a.X0,b.X0,temp),temp))) (still not 100% sure we're guaranteed execution happening in correct order there w/ regards to temp), and can just be calculated when we want it. Stroking a path along quat4.subtract(a.X0,b.X0,temp) from a.X0 will draw you a ruler.

Schroedingers-Hat commented 13 years ago

Added some methods to inertialObject, the rest can go in whatever handles the interface.

For more complicated stuff, like multi-point paths or light delayed rulers we can just construct our ruler out of inertialobjects

capnrefsmmat commented 13 years ago

This got lost in the arbitrarypaths merge, and we need to figure out exactly what we want of this code.

Schroedingers-Hat commented 13 years ago

As I said above, for what you originally asked (distance between A and B in current frame, just do the maths in the function that displays it. Something along the lines of: quat4.subtract(thing1.COM.X0,thing2.COM.X0,temp); then display sqrt(spacedot(temp,temp)); where you want it

capnrefsmmat commented 13 years ago

That sounds good. Here's my potential use-cases:

Clearly this would only be sensical in the showFramePos mode, since light-delayed rulers would confuse users more than they'd help them.

It sounds like this is something that could easily be built into demos; provide the objects or points which should be the ruler endpoints, and the ruler is constructed with a reference to its endpoints. It draws itself on the screen as a little ruler labeled with the distance.

Schroedingers-Hat commented 13 years ago

deleted last response because it was wrong and don't want either of use getting confused again.

@capnrefsmmat rulers.js is pretty much done, need to integrate it into demos.js and make its output pretty. I settled on making available: the distance in your frame this.distances[0], and the distance and time between those events in the other two frames distances[1 and 2] times[1 and 2], so it may be useful for pointing out both simultenaety and contraction. The time they point to is the time that the vertex of the object pointed to is synchronous with you, not the centre of mass.

The only other piece of information I can think that might be useful is: "How far, according to the version of object A that is syncronous with me, is it to object B, whenever that might be for B", but that's probably a bit of an advanced topic, as it involves both contraction and simultenaety, and gets even more confusing if they are moving in different directions. One thing it may be useful for is 'how far away from home is the travelling twin in his frame' or similar.

Schroedingers-Hat commented 13 years ago

@capnrefsmmat almost forgot. Will start looking into units, when that's done we can put tick marks on the ruler that correspond to actual units. Was thinking we could use scene.zoom, logs and rounding to choose the closest power of 10 times a metre, then use gamma to put matching tick marks for the other frames.

capnrefsmmat commented 13 years ago

That sounds good. I have some units-related ideas I'll post in that issue.

Schroedingers-Hat commented 12 years ago

Random thought. Dragable/rotatable ruler (with self-correcting scale) as part of the ui.

capnrefsmmat commented 12 years ago

Or maybe an overlaid scale grid?

Schroedingers-Hat commented 12 years ago

That's a far better idea. Knew I kept you around for a reason.

I've even done the maths for it already -- including the ability for the grid to rotate. It's buried in the minkowski drawing code in extendedObject right now, I'll dig it out when I rewrite things to make integrating polygons less kludgy.

capnrefsmmat commented 12 years ago

Shiny. It's probably not hard to draw the grid on a separate canvas and draw the rest of the scene on top of it, like you do with the Minkowski diagrams.

Schroedingers-Hat commented 12 years ago

My thought was for the grid on top, oscilloscope style. Slightly more functional for fine measurements, but not as nice looking. I suppose a switch would be trivial to make it either.

capnrefsmmat commented 12 years ago

Yeah, it's just a matter of which canvas you draw onto which.