A Processing project to render
You'll find three different versions of the sketch in the source
folder: codename 3daxis
, codenme 3dfunc
and codename 3ddiff
.
-
3daxis
is the basic version that offers the features to render simple concepts, points and lines, through the Desk instructions, with basic navigation functionalities. -
3dfunc
is the first big revision, it includes all the features of the3daxis
version, plus the ability to define and plot single variabile linear functions graphs through the Desk instructions, with enhanced navigation functionalities. -
3ddiff
is the latest revision, it includes all the features of the3dfunc
version, plus the ability to plot a graph of the differential equation that describes the mechanics of a pendulum using theplane as a (sort of) phase space in which the coordinates represents the pendulum angle , and the coordinates the angular velocity of the pendulum.
The following specifications are referred to every versions, each section will include a separate paragraph for functionalities specific to the 3dfunc
and 3ddiff
versions.
By default, this sketch renders the three axis
You can interact with the space using the following hotkeys:
-
r
: start and stop generating random points within the a certain scope. -
a
: hide and show the axis. -
o
: hide and show the origin. -
d
: switch between themes. -
l
: render the points as vectors (show a line connecting them with the origin). -
c
: delete all points except the axis and the other fundamental vectors. -
i
: reset to default values. -
u
: parse Desk instructions. -
ARROW UP
: rotate everything around theaxis by . -
ARROW DOWN
: rotate everything around theaxis by . -
ARROW LEFT
: rotate everything around theaxis by . -
ARROW RIGHT
: rotate everything around theaxis by . -
CONTROL
: rotate everything around theaxis by . -
SHIFT
: rotate everything around theaxis by .
-
v
: hide and show labels globally -
f
: enable function mode, resets the space to default values, then sets the rotation ataround every axis, thus facing the plane parallelly, with maximum zoom value -
1 ... 9
: sets the zoom to a value from1
(farthest away from the origin) to9
(closest to the origin). Zoom values can be set at any time without resetting the space, every entity already on display will be scaled accordingly to the new zoom value
You can interact with the 3D space at runtime by adding objects to it.
To do so, you'll have to write a Desk file at path cdw\desk.txt
, and use the designated hotkey to load contents from it.
Desk can be thought of as a decriptive languange made up of instructions and parameters that can be parsed by the rendering system. Parameters are order-sensitive. A Desk file must contain every instruction separated by a new line (empty lines are skipped). Bad syntaxt will result in an error message followed by the number of line where the parsing error occourred.
-
point X Y Z [Att Lab]
Thepoint
instruction adds a point to the 3D space.
This instruction takes up to 5 arguments:-
X
,Y
andZ
are floats, they represent the absolute coordinates of the point you want to add. -
Att
is an [optional] intager, it representes the index of the point you want to attach to this new point. Index 0 means no attachment, index 1 is the first point in the file. You cannot attach a point to fundamental vectors. -
Lab
is an [optional] string, it representes the label of the point.
-
-
line A B C VX VY VZ [Lab]
Theline
instruction adds a line to the 3D space.
A line in ℝ³ is a set of points determinted by a pointand a directional vector as such .
This instruction takes up to 7 arguments:-
A
,B
andC
are floats, they represents the coordinates of the point -
VX
,VY
andVZ
are floats, they represents the compontents of the directional vector -
Lab
is an [optional] string, it representes the label of the point.
-
-
func an ... a0 [z=Z]
Thefunc
instructions plots the graph of the single variable linear function defined in the following form:. This instructions has a variable number of parameters: -
an ... a0
are floats, they represent the coefficient of the. You need to specify at least one coefficient. -
Z
is an [optional] float, it represents the costantvalue to plot the function to. If no Z
value is specified, all the points will have theircoordinate set to .
Each plotted function will show a label of its equation.
Note that every function is plotted by calculating itswith with (basically between and every ). To change this behaviour, you can set your own values for the limit
andstep
variables in thevoid y_function(float _z, float[] lambda)
method. -
-
diff [th1 th2 th_dot t delta_t g mu z scale]
Thediff
instruction plots the graph of the differential equation that describes the pendulum mechanicson the plane as a (sort of) phase space. You can use the parameters to tweak the graph. If no additional parameter is specified, the default values are set as follows: . Please note that you can either specify no parameter at all or all of them. -
th1
andth2
are a floats, they represents respectively theand coefficents in the initial value . This value represents the angle of the pendulum in radiants, and it's the component of the vector. -
th_dot
is a float, it represents the initialvalue. This value represents the angular velocity of the pendulum, and it's the component of the vector. -
t
is a float, it represents the total time of observation; the biggert
, the more points the graph will have with a givendelta_t
value. -
delta_t
is a float, it represents the step of time at which each observation (or calculation) is executed; the lower thedelta_t
, the more points the graph will have with a givent
value. Thedelta_t
value has a huge impact on the graph's precision, it's recommended to use values. -
g
is a float, it represents the gravity force in. -
mu
is a float, it represents the air resistance in. -
z
is a float, it represents the fixedvalue each vector in the differential equation will have. -
scale
is a float, it represents the value to scale theand coordinates of all the vectors in the differential equation by.
Each plotted differential equation will result in
t
\delta_t
points. While a huge quantity of points won't necessarily be a problem per se, please note that large quantities of points can result in slow downs while using the navigation functionalities such as real-time rescaling and rotation, as well as and increase of the process' memory usage. -
Please have a look at the Desk Example section.
My intent with this project is to create a generalized and modular system to project ℝ³ vectors into a 2D plane, and play around with them.
Any ℝ³ vector is represented by an object of the point
class; the point
class contains a PVector v
that stores the point's coordinates, and a bunch of methods, its rotation functions and its drawing functions.
For the purpose of keeping it all simple, there's only one ArrayList structure points
that stores every ℝ³ vector.
This means of course, that points
stores also fundamental points, such as:
-
[index 0]
the Origin vector -
[index 1]
the Offset vecotr, that is the vector containing theand offset to logically "move" the origin of reference to the center of the window, instead of the default top-left conrner -
[index 2]
theAxis -
[index 3]
theAxis -
[index 4]
theAxis I believe this design choice significantly reduces complexity by removing the need for other global variables.
In the 3ddiff
revision, for convenience, the mathematical concept of "differential equation" is impelemented as a new class diff_eq
that contains all and only the attributes and methods directly related to differential equations (such as calculating the diff_eq
class is nothing more than an higher level of abstraction that ultimately relies on the sole "meaningful" data structure, that is the point
class. Even the methods used to add the equation's points the system are of course the ones already defined in the point
class.
I'd like to think of this addition not as a structural change in the program's functionalities, but rather as a new, separate, "block" that is able to work on top of the already existing system without the need to change its core.
This is the main reason I'm treating every update as a new, distinct revision of the sketch; the basic 3daxis
version one is already capeable of everything, since everything in
My goal with this project is to keep adding new abstractions and features to ultimately create a full fledged
Every major functionality upgrade will come in as a separate revision of the sketch.