python3 recursion animation - recursion

I need to animate a similar animation in quickdraw and I'm told to use recursion. I'm having a hard time with the orbits and this is the code I have for orbiting circle but I have no idea how to use recursion to create the above image.
import math
print("circle",400,300,50)
print("flush false")
centreX=400
centreY=300
radius=100
angle=math.pi/2
while True:
print("color 0 0 0")
print("clear")
print("color 255 0 255")
print("circle",centreX,centreY,radius)
childX=math.sin(angle)*radius*1.5+centreX
childY=math.cos(angle)*radius*1.5+centreY
print("circle",childX,childY,radius/2)
print("refresh")
angle+=0.01
the data file looks like this:
RootObject: Sun
Object: Sun
Satellites: Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune,Ceres,Pluto,Haumea,Makemake,Eris
Radius: 20890260
Orbital Radius: 0
Object: Miranda
Orbital Radius: 5822550
Radius: 23500
Period: 1.413
Object: Ariel
Orbital Radius: 8595000
Radius: 60000
Period: 2.520379
Object: Umbriel
Orbital Radius: 11983500
Radius: 60000
Period: 4.144177
Object: Titania
Orbital Radius: 19575000
Radius: 75000
Period: 8.7058
Object: Oberon
Orbital Radius: 26235000
Radius: 75000
Period: 13.463
Object: Uranus
Orbital Radius: 453572956
Radius: 2555900
Period: 30799
Satellites: Puck,Miranda,Ariel,Umbriel,Titania,Oberon
Object: Neptune
Orbital Radius: 550000000
Radius: 2476400
Period: 60190
Satellites: Triton
Object: Triton
Orbital Radius: 40000000
Radius: 135300
Period: -5.8
Object: Mercury
Orbital Radius: 38001200
Period: 87.9691
Radius: 243900.7
Object: Venus
Orbital Radius: 57477000
Period: 224.698
Radius: 605100.8
Object: Earth
Orbital Radius: 77098290
Period: 365.256363004
Radius: 637100.0
Satellites: Moon
Object: Moon
Orbital Radius: 18128500
Radius: 173700.10
Period: 27.321582
Object: Mars
Orbital Radius: 106669000
Period: 686.971
Radius: 339600.2
Satellites: Phobos,Deimos
Object: Phobos
Orbital Radius: 3623500.6
Radius: 200000
Period: 0.31891023
Object: Deimos
Orbital Radius: 8346000
Period: 1.26244
Radius: 200000.2
Object: Jupiter
Orbital Radius: 210573600
Period: 4332.59
Radius: 7149200
Satellites: Io,Europa,Ganymede,Callisto
Object: Ceres
Orbital Radius: 130995855
Period: 1679.67
Radius: 48700
Object: Io
Orbital Radius: 22000000
Period: 1.7691377186
Radius: 182100.3
Object: Europa
Orbital Radius: 36486200
Period: 3.551181
Radius: 156000.8
Object: Ganymede
Orbital Radius: 47160000
Period: 7.15455296
Radius: 263400
Object: Callisto
Orbital Radius: 69700000
Period: 16.6890184
Radius: 241000
Object: Saturn
Orbital Radius: 353572956
Period: 10759.22
Radius: 6026800
Satellites: Mimas,Enceladus,Tethys,Dione,Rhea,Titan,Iapetus
Object: Mimas
Orbital Radius: 8433396
Radius: 20600
Period: 0.9
Object: Enceladus
Orbital Radius: 10706000
Radius: 25000
Period: 1.4
Object: Tethys
Orbital Radius: 13706000
Radius: 50000
Period: 1.9
Object: Dione
Orbital Radius: 17106000
Radius: 56000
Period: 2.7
Object: Rhea
Orbital Radius: 24000000
Radius: 75000
Period: 4.5
Object: Titan
Orbital Radius: 50706000
Radius: 257600
Period: 15.945
Object: Iapetus
Radius: 75000
Orbital Radius: 72285891
Period: 79
I'm supposed to import the data into a recursive function to create the orbits and the animation but I have no idea how. I've tried almost everything, Its very frustrating.
Would this code work?
print("flush false")
scale=250/max([dict[x]["Orbital Radius"] for x in dict if "Orbital Radius" in dict[x]])
t=0
x=400
y=300
while True:
print("refresh")
print("colour 0 0 0")
print("clear")
print("colour 255 255 255")
print("fillcircle",x,y,dict['Sun']['Radius']*scale)
print("text ", "\"Sun\"",x+dict['Sun']['Radius']*scale,y)
r_earth=dict['Earth']['Orbital Radius']*scale;
print("circle",x,y,r_earth)
r_X=x+math.sin(t*2*math.pi/dict['Earth']['Period'])*r_earth
r_Y=y+math.cos(t*2*math.pi/dict['Earth']['Period'])*r_earth
print("fillcircle",r_X,r_Y,dict['Earth']['Radius']*scale)
print("text ", "\"Earth\"",r_X+dict['Earth']['Radius']*scale,r_Y)
t+=0.02

Related

Sparse array filled with constant in Julia

I have a matrix, M, with very simple form: M[i,j]=a if i==j and M[i,j]=b everywhere else. M is very large (>10000) so I cannot initialize it or store it without using some sort of sparse matrix. It seems that the best way to store this matrix would be to use some sort of sparse matrix where non-entries are set to b instead of zero.
I have tried
M = spdiagm((a-b), N, N) .+ b
But doing it this way stores M as a 10 by 10 matrix with 100 entries which seems to mean that there is no compression.
Is there a better way to initialize this matrix?
It depends on what you want to do with your matrix, but if you are only interested in performing matrix-vector products, you can use the FillArrays.jl package in conjunction with the LinearMaps.jl package:
julia> using LinearMaps, FillArrays
julia> n=100 # can be bigger
100
julia> a=2.0
2.0
julia> b=3.0
3.0
julia> M=(a-b)*LinearMap(Eye(n,n))+b*LinearMap(Ones(n,n))
100×100 LinearMaps.LinearCombination{Float64} with 2 maps:
100×100 LinearMaps.ScaledMap{Float64} with scale: -1.0 of
100×100 LinearMaps.WrappedMap{Float64} of
100×100 Eye{Float64}
100×100 LinearMaps.ScaledMap{Float64} with scale: 3.0 of
100×100 LinearMaps.WrappedMap{Float64} of
100×100 Ones{Float64}
Then you can perform operations like
julia> x=rand(n);
julia> M*x;
julia> x'*M;
julia> M*M
100×100 LinearMaps.CompositeMap{Float64} with 2 maps:
100×100 LinearMaps.LinearCombination{Float64} with 2 maps:
100×100 LinearMaps.ScaledMap{Float64} with scale: -1.0 of
100×100 LinearMaps.WrappedMap{Float64} of
100×100 Eye{Float64}
100×100 LinearMaps.ScaledMap{Float64} with scale: 3.0 of
100×100 LinearMaps.WrappedMap{Float64} of
100×100 Ones{Float64}
100×100 LinearMaps.LinearCombination{Float64} with 2 maps:
100×100 LinearMaps.ScaledMap{Float64} with scale: -1.0 of
100×100 LinearMaps.WrappedMap{Float64} of
100×100 Eye{Float64}
100×100 LinearMaps.ScaledMap{Float64} with scale: 3.0 of
100×100 LinearMaps.WrappedMap{Float64} of
100×100 Ones{Float64}
The matrices are stored using a "lazy" approach and not expanded in the memory, hence n can be big. However one must take care that M is not an AbstractMatrix :
julia> supertype(typeof(M))
LinearMap{Float64}

Calculating the height of a CSS 3D rotationX transform

I'd like to find out the height of an element, of a specific width and height, after a rotationX transform has been applied to it.
Would be ideal to be able find out the angle of an element's rotationX transform given the desired height.
rotateX() preserves the x-coordinate. The y-coordinate scales with the cosine of the rotation angle:
new_height = old_height * cos(angle)
The other way around is:
angle = arc cos(new_height / old_height)
Found 2 ways on finding dimensions of a DOM element after css 3D transforms have been applied to it.
1.By using element.getBoundingClientRect() which will return a ClientRect object with the correct dimensions of an elements after the transforms has been applied to it
{
bottom: 90.07061767578125
height: 90.07061767578125
left: 0
right: 891
top: 0
width: 891
}
A module called domvertices will return the xyz positions of 4 corner vertices for a DOM element, accounting for any transformatons:
{
a: {x: , y: , z: },
b: {x: , y: , z: },
c: {x: , y: , z: },
d: {x: , y: , z: }
}

Extract data points of figure file in MAT LAB

I have imported a shape file and save it as a MAT LAB figure file. I need to extract data points along the boundary of the figure file as (x,y) coordinates. can someone help me with this!
It depends on your figure (2D image, 3D image , chart ,...).
You can read a fig files by this command
>> figFile = load('1.fig','-mat')
figFile =
hgS_070000: [1x1 struct]
after that you can find all data in this structure by using dot
>> figFile.hgS_070000
ans =
type: 'figure'
handle: 1
properties: [1x1 struct]
children: [1x1 struct]
special: []
>> figFile.hgS_070000.children
ans =
type: 'axes'
handle: 176.08251953125
properties: [1x1 struct]
children: [1x1 struct]
special: [4x1 double]
>> figFile.hgS_070000.children.children
ans =
type: 'graph2d.lineseries'
handle: 177.0830078125
properties: [1x1 struct]
children: []
special: []
>> figFile.hgS_070000.children.children.properties
ans =
Color: [0 0 1]
XData: [1 2 3 4 5 6 7 8 9]
YData: [2 1 5 6 4 8 8 4 8]
ApplicationData: [1x1 struct]
.
.
.
Ploted data can be extracted by this
>> Y = figFile.hgS_070000.children.children.properties.YData
>> X = figFile.hgS_070000.children.children.properties.XData

Idrisi - how can I convert x/y into lat/long?

I have coordinates (Idrisi) x: 550000, 580000 y: 4840000, 4810000, but I need latitude and longitude... how can I convert it? :(
Thanx

What are the best methods to measure velocity given

Given that you have thousands of 3D vectors with their time of insertion, and you want to find the instantaneous velocity at the current time? Also, the primary criterion is accuracy, with the secondary criterion being performance.
Sample data:
t is in milliseconds (low resolution)
:> t: 19624, x: -221.68, y: 394.46, z: 127.66
:> t: 19656, x: -222.07, y: 394.26, z: 127.54
:> t: 19671, x: -222.47, y: 394.06, z: 127.43
:> t: 19687, x: -222.53, y: 394.03, z: 127.36
:> t: 19718, x: -222.95, y: 393.81, z: 127.23
:> t: 19734, x: -222.95, y: 393.81, z: 127.23
:> t: 19749, x: -223.42, y: 393.58, z: 127.05
:> t: 19765, x: -223.42, y: 393.58, z: 127.05
:> t: 19796, x: -223.86, y: 393.36, z: 126.91
:> t: 19812, x: -224.30, y: 393.13, z: 126.77
:> t: 19827, x: -224.36, y: 393.11, z: 126.71
:> t: 19843, x: -224.36, y: 393.11, z: 126.71
:> t: 19858, x: -224.82, y: 392.87, z: 126.55
:> t: 19874, x: -225.27, y: 392.65, z: 126.48
:> t: 19890, x: -225.32, y: 392.63, z: 126.49 [current time]
velocity with respect to OX, OY and OZ axes is the second derivative of x(t), y(t) and z(t).
The first defivative (suppose t=1) if easy to find
x'(1) = x(1) - x(0)
and
x''(2) = x'(2) - x'(1)
it will be fast enough but it wount be accurate. So I recoment you to approximate the series of x(t) with continious function (polynom), and calculate the second derivative of that polynom. Try to read about interpolation polynomes here.

Resources