How can I get the coordinates of some point on an already-settled Graph? - manim

In manim, I want to get the coordinates of a certain point on a graph?
class Formula2(GraphScene):
CONFIG = {
"x_min" : 0,
"x_max" : 100.3,
"x_tick_frequency": 10,
"y_min" : 0,
"y_max" : 100.3,
"y_tick_frequency": 10,
"graph_origin" : [-4,-3,0] ,
"function_color" : RED ,
"axes_color" : WHITE ,
"x_labeled_nums" : range(10,100,10),
"y_labeled_nums" : range(10,100,10)
}
def construct(self):
self.setup_axes(animate=True)```
What's my next method or function?

You can use the method coords_to_point, more details in my video

Related

How to track parameter during Transformation of graph

Let's say I'm trying to transform one function into another:
y=x -> y=2x
Is there a way where I can 'follow' the m parameter during the animation, and show it on the screen?
Example: GIF of me doing it in GeoGebra
See my tutorial here
More ValueTracker examples here
Solution:
class ValueTrackerExample(Scene):
def construct(self):
# SETUP GRAPH
axes = Axes()
m_tracker = ValueTracker(1)
func = lambda m: lambda x: m * x
graph = VMobject()
graph_kwargs = {"color": GREEN}
# SETUP FORMULA
decimal = DecimalNumber(1,num_decimals=2)
formula = TexMobject("y = ", "x")
# ---- Arrange position of formula
formula.to_corner(DR)
formula[0].shift(LEFT * 1.1)
decimal.next_to(formula[1],LEFT,aligned_edge=DOWN)
# SET UPDATERS
def update_graph(mob):
mob.become(
axes.get_graph(
func(m_tracker.get_value()),
**graph_kwargs
)
)
# SET INITIAL STATE OF GRAPH
update_graph(graph)
graph.add_updater(update_graph)
self.add(axes)
self.play(ShowCreation(graph),Write(VGroup(formula[0],decimal,formula[1])))
self.play(
m_tracker.set_value, 2,
ChangeDecimalToValue(decimal,2)
)

How to apply an updater to a Line connected to a function graph

Here's my code
class Formula2(GraphScene):
CONFIG = {
"x_min" : 0,
"x_max" : 10.3,
"x_tick_frequency": 1,
"y_min" : 0,
"y_max" : 10.3,
"y_tick_frequency": 1,
"graph_origin" : [-4,-3,0] ,
"function_color" : RED ,
"axes_color" : WHITE ,
"x_labeled_nums" : range(1,10,1),
"y_labeled_nums" : range(1,10,1)
}
def construct(self):
self.setup_axes(animate=True)
func_graph = self.get_graph(self.func_to_graph, self.function_color)
vert_line = Line(start=self.coords_to_point(1,0), color=YELLOW)
vert_line.add_updater(lambda d:d.put_start_and_end_on(vert_line.start, self.input_to_graph_point(self.point_to_coords(vert_line.start)[0], func_graph)))
self.play(ShowCreation(func_graph))
self.play(ShowCreation(vert_line))
self.play(ApplyMethod(vert_line.shift, RIGHT))
def func_to_graph(self,x):
return x
And the updater doesn't work. I want the start of the line be on the x-axis and its end on the function graph. What's the problem with my code?
class Formula2(GraphScene):
CONFIG = {
"x_min" : 0,
"x_max" : 10.3,
"x_tick_frequency": 1,
"y_min" : 0,
"y_max" : 10.3,
"y_tick_frequency": 1,
"graph_origin" : [-4,-3,0] ,
"function_color" : RED ,
"axes_color" : WHITE ,
"x_labeled_nums" : range(1,10,1),
"y_labeled_nums" : range(1,10,1)
}
def construct(self):
self.setup_axes(animate=False)
func_graph = self.get_graph(self.func_to_graph, self.function_color)
vert_line = Line(start=self.coords_to_point(1,0), color=YELLOW)
vert_line.add_updater(
lambda mob: mob.put_start_and_end_on(
vert_line.get_start(),
func_graph.get_end()
)
)
self.play(ShowCreation(func_graph))
# add the vert_line because it have a updater method
self.add(vert_line)
self.play(ShowCreation(vert_line))
self.play(ApplyMethod(vert_line.shift, RIGHT))
def func_to_graph(self,x):
return x

Parsing text file - Lua

I have a text file contains:
<Response>
<IP>17.178.96.59</IP>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<RegionCode></RegionCode>
<RegionName></RegionName>
<City>Chicago</City>
<ZipCode></ZipCode>
<TimeZone>America/Chicago</TimeZone>
<Latitude>37.751</Latitude>
<Longitude>-97.822</Longitude>
<MetroCode>0</MetroCode>
</Response>
How to remove each and so I get only:
17.178.96.59,
US,
United States,
nil,
nil,
Chicago,
nil,
America/Chicago,
37.751,
-97.822,
0
Using the Lua script.
You don't show what you already tried, but there is a recently discussed SO question on how to iterate over XML nodes that should work well for your purposes. Just replace fixed element names with something like [%w_]+ and collect parsed values into a table and you'll get the result you are looking for.
This is what I am trying to do.
int = getInternet()
url3 = 'https://freegeoip.app/xml/17.178.96.59'
result = int.getURL(url3)
result = result:gsub("><",">nil<"):gsub("<.->",""):gsub("%c%s+",","):sub(2)..'nil'
print(result)
-- = 17.178.96.59,US,United States,nil,nil,nil,nil,America/Chicago,37.751,-97.822,0,mil
geoResult = {}
for word in string.gmatch(result, '([^,]+)') do
--print(word)
table.insert(geoResult, word)
--for i,v in ipairs(result) do print(i,v) end
end
print('IP : '..geoResult[1])
print('Country ID : '..geoResult[2])
print('Country Name : '..geoResult[3])
print('Region Code : '..geoResult[4])
print('Region Name : '..geoResult[5])
print('City : '..geoResult[8])
print('ZIP Code : '..geoResult[7])
print('Time Zone : '..geoResult[8])
print('Latitude : '..geoResult[9])
print('Longitude : '..geoResult[10])
print('Metro Code : '..geoResult[11])
-- result:
17.178.96.59,US,United States,nil,nil,nil,nil,America/Chicago,37.751,-97.822,0,nil
IP : 17.178.96.59
Country ID : US
Country Name : United States
Region Code : nil
Region Name : nil
City : America/Chicago
ZIP Code : nil
Time Zone : America/Chicago
Latitude : 37.751
Longitude : -97.822
Metro Code : 0

What are the GLTF animations sampler input/output values?

I am reading the specification, but I can not understand the properties of the sampler.
This is the animation that I have
"animations" : [
{
"channels" : [
{
"sampler" : 0,
"target" : {
"node" : 0,
"path" : "translation"
}
}
],
"name" : "00001_2780.datAction",
"samplers" : [
{
"input" : 9,
"interpolation" : "CUBICSPLINE",
"output" : 10
}
]
},
{
"channels" : [
{
"sampler" : 0,
"target" : {
"node" : 1,
"path" : "translation"
}
}
],
"name" : "00002_2780.datAction",
"samplers" : [
{
"input" : 9,
"interpolation" : "CUBICSPLINE",
"output" : 11
}
]
}
],
What I can not understand is what are the values 9 and 10 for the first sample and 9 and 11 for the second
All that we have in the specification is
https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
Each of the animation's samplers defines the input/output pair: a set of floating point scalar values representing linear time in seconds; and a set of vectors or scalars representing animated property.
And this makes it more unclear to me.
Is there a more detailed explanation about what input/output values are and what they represent. What will happen for example if I change the input from 9 to 99 or to 9.9 or to 0.9 or to 0. How will this change the animation?
Thanks
The numbers 9 and 10 here are glTF accessor index ID values. If you decode accessor index 9, you'll find the list of times for each of the keyframes of the animation. If you decode accessor 10, normally you would expect to find the list of values for the keyframes. But since this is CUBICSPLINE, accessor 10 will contain the in-tangent, value, and out-tangent for each keyframe.
One way to investigate glTF files like this is to use the glTF Tools extension for VSCode. You can right-click the input or output value and choose Go To Definition to get to the accessor in question, and choose Go To Definition again to decode it. (Disclaimer, I'm a contributor to glTF Tools).

Docker API: cpu_stats vs percpu_stats

What is the difference between
cpu_stats and percpu_stats when using Docker remote API:
The request is :
GET /containers/(id or name)/stats
(A part of) The response is:
"cpu_stats" : {
"cpu_usage" : {
"percpu_usage" : [
8646879,
24472255,
36438778,
30657443
],
"usage_in_usermode" : 50000000,
"total_usage" : 100215355,
"usage_in_kernelmode" : 30000000
},
"system_cpu_usage" : 739306590000000,
"throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0}
},
"precpu_stats" : {
"cpu_usage" : {
"percpu_usage" : [
8646879,
24350896,
36438778,
30657443
],
"usage_in_usermode" : 50000000,
"total_usage" : 100093996,
"usage_in_kernelmode" : 30000000
},
"system_cpu_usage" : 9492140000000,
"throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0}
}
Example taken from Docker docs:
https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#get-container-stats-based-on-resource-usage
When testing with a sample container, values are almost the same.
Example of an output:
#Cpu stas
{u'cpu_usage': {u'usage_in_usermode': 0, u'total_usage': 36569630, u'percpu_usage': [8618616, 3086454, 16466404, 8398156], u'usage_in_kernelmode': 20000000}, u'system_cpu_usage': 339324470000000, u'throttling_data': {u'throttled_time': 0, u'periods': 0, u'throttled_periods': 0}}
#Per cup stats
{u'cpu_usage': {u'usage_in_usermode': 0, u'total_usage': 36569630, u'percpu_usage': [8618616, 3086454, 16466404, 8398156], u'usage_in_kernelmode': 20000000}, u'system_cpu_usage': 339320550000000, u'throttling_data': {u'throttled_time': 0, u'periods': 0, u'throttled_periods': 0}}
I tried also to compare specific metrics in the two case for 4 containers:
#First container
359727340000000 #CPU Stats
359723390000000 #Per CPU Stats
#2
359735220000000
359731290000000
#3
359743100000000
359739170000000
#4
359750940000000
359747000000000
The values above are almost same (some differences but not huge - may be because there are some ms between each request.)
In the official documentation:
The precpu_stats is the cpu statistic of last read, which is used for
calculating the cpu usage percent. It is not the exact copy of the
“cpu_stats” field.
Not very clear for me.
Anyone could explain better ?

Resources