Core Animation - How to calculate duration so that two lines of different length are drawn at the same rate - objective-c

I have two lines at different lengths
Line1 -----
Line2 -------------
How can I calculate the animation duration for each line so that they both are drawn at the same speed.
At the moment, I have a set value for duration
line1.duration = 1;
line2.duration = 1;
Because of the different lengths, line1's animation is slower than line2.
How can I calculate the animation duration with a fixed speed?
EDIT
Forgot to mention that line1 doesn't know line2's length as the lines are drawn in a loop. What i'm after is a constant velocity calculation / pixels per seconds

Try this:
line2.duration = lengthOfLine2 / lengthOfLine1 * line1.duration;
(substitute the appropriate values.)

I am assuming: Drawing at same rate - You mean both of them should end drawing simultaneously.
Suppose Line 1 : Length - 100 px
Suppose Line 2 : Length - 350 px
Then suppose 1 px takes 1 ms then Line 1 will take 100 ms
For Line 2 to take 100 ms it needs to draw (350/100 = 3.5 px/ms)
So suppose Short line takes time "t" for line of length "l1"
Then greater line should take time "l2/t" for line of length "l2"
for both of them to stop drawing simultaneously.

Related

add horizontal Line in existing Trend Indicator

I am using the MTrendSqueeze Indicator which is based on a simple moving average value.
I want TradingView to draw a line, once this condition is met:
Barclose divided through current trend indicator value = 50 or less
That means in the example picture it would be:
4,89 / 0.2 = 24,45
It´s less than 50, so draw a line there
MTrend example

Plotting data from two sets with different shapes in the same plot

I am using data collected from two different instruments which have different resolution because of the sampling rate of each instrument. For a specific time, one of the sets have >10k entries while the other has ~2.5k. They however capture data over the same time interval, and I want to plot them on top of each other even though they have different resolution in data. The minimum and maximum x of both sets are the same however one of them have more entries.
Simplified it could look like this:
1st set from instrument with higher sampling rate:
time(s) value
0.0 10
0.2 11
0.4 12
0.6 13
0.8 14
... ..
100 50
2nd set from instrument with lower sampling rate:
time(s) value
0 100
1 120
2 125
3 128
4 130
. ...
100 430
They are measuring different things, but I would like to display them in the same plot. How can I accomplish this?
I found the mistake.. I was trying to plot both datasets using the time data from the first instrument. Of course they need to be plotted with their respective time data and I put the first time data in the second plot by mistake..

Graph to show departure and arrival times between stations

I have the start and end times of trips made by a bus, with the times in an Excel sheet. I want to make the graph as below :
I tried with Matlab nodes and graphs but did not got the exact figure, below is the Matlab code which I tried as an example:
A = [1 4]
B = [2 3]
weights = [5 5];
G = digraph(A,B,weights,4)
plot(G)
And the figure it generates:
I have got many more than 4 points in the Excel sheet, and I want them to all be displayed as in the first image.
Overview
You don't need any sort of complicated graph package for this, just use normal line plots! Here are methods in Excel and Matlab.
Excel
Give each bus stop a number, and list the bus stop number by the time it arrives/leaves there. I'll use stops number 0 and 1 for this example.
0 04:41
1 05:35
1 05:40
0 06:34
0 06:51
1 07:45
1 15:21
0 16:15
Then simply highlight the data and insert a "scatter with straight lines"
The rest is formatting. You can format the y-axis and tick "values in reverse order" to get the time increasing as in your desired plot. You can change the x-axis tick marks to just show integer stop numbers, get rid of the legend etc.
Final output:
Matlab
Here is the Matlab documentation for converting Excel formatted dates into Matlab datetime arrays: Convert Excel Date Number to Datetime.
Once you have the datetime objects, you can do this easily with the standard plot function.
% Set times up as a datetime array, could do this any number of ways
times = datetime(strcat({'1/1/2000 '}, {'04:41', '05:35', '05:40', '06:34', '06:51', '07:45', '15:21', '16:15'}, ':00'), 'format', 'dd/MM/yyyy HH:mm:ss');
% Set up the location of the bus at each of the above times
station = [0,1,1,0,0,1,1,0];
% Plot
plot(station, times) % Create plot
set(gca, 'xtick', [0,1]) % Limit to just ticks at the 2 stops
set(gca, 'ydir', 'reverse') % Reverse y axis to have earlier at top
set(gca,'XTickLabel',{'R', 'L'}) % Name the stops
Output:

how can i plot a graph in in vb to to show a large amount of data

I want to plot graph to show the difference of Net connectivity in one hour . i found the average speed of One hour and the different between the Speed. and i add the difference percentage in a ListBox . I have to show the numbers in graph of one hour ? How can I Plot the Graph Any Suggestion Please .
enter code here
Dim Per As Double
For x As Integer = 0 To ListBox2.Items.Count - 1
Per = Math.Abs((avg - Val(ListBox2.Items.Item(x).ToString)) / (avg)) * 100
ListBox3.Items.Add(Per)
i have to plot all the number of ListBox3 contains more than 3000.
i found it...
For y As Integer = 0 To ListBox3.Items.Count - 1
s.Points.AddXY(y, Val(ListBox3.Items.Item(y).ToString))
Next
Chart1.Series.Add(s)

How to Resize using Lanczos

I can easily calculate the values for sinc(x) curve used in Lanczos, and I have read the previous explanations about Lanczos resize, but being new to this area I do not understand how to actually apply them.
To resample with lanczos imagine you
overlay the output and input over
eachother, with points signifying
where the pixel locations are. For
each output pixel location you take a
box +- 3 output pixels from that
point. For every input pixel that lies
in that box, calculate the value of
the lanczos function at that location
with the distance from the output
location in output pixel coordinates
as the parameter. You then need to
normalize the calculated values by
scaling them so that they add up to 1.
After that multiply each input pixel
value with the corresponding scaling
value and add the results together to
get the value of the output pixel.
For example, what does "overlay the input and output" actually mean in programming terms?
In the equation given
lanczos(x) = {
0 if abs(x) > 3,
1 if x == 0,
else sin(x*pi)/x
}
what is x?
As a simple example, suppose I have an input image with 14 values (i.e. in addresses In0-In13):
20 25 30 35 40 45 50 45 40 35 30 25 20 15
and I want to scale this up by 2, i.e. to an image with 28 values (i.e. in addresses Out0-Out27).
Clearly, the value in address Out13 is going to be similar to the value in address In7, but which values do I actually multiply to calculate the correct value for Out13?
What is x in the algorithm?
If the values in your input data is at t coordinates [0 1 2 3 ...], then your output (which is scaled up by 2) has t coordinates at [0 .5 1 1.5 2 2.5 3 ...]. So to get the first output value, you center your filter at 0 and multiply by all of the input values. Then to get the second output, you center your filter at 1/2 and multiply by all of the input values. Etc ...