I am working on a circular timer in iOS. The circle should contain a 24 hour cycle.
The picture below shows how i intend to change the time of the timer.
Instead of the position in degrees of the slider, I want to display the time accordingly to the position of the slider, but I'm kinda struggling to find the right formula. Does anyone have an idea how to tacke this?
Thank you in advance!
Granit
Trick some mathematical formulas;
like 360 / 24 = 15, it means for 1 hour it rotates 15 degree,
so calculate for the others:
1 hour = 15 degree
2 hours = (15 * 2) = 30 degree and so on....
...
24 hours = (15 * 24) = 360 degree.
So if you get 273 value, it means
273/24 = int (11.375) = 11 hours
Related
In my model, I am saving results from numerous Parameter Variation runs in a Histogram Data object.
Here are my Histogram Data settings:
Number of intervals: 7
Value range:
Automatically detected
Initial Interval Size: 10
I then print out these results using the following :
//if final replication, write Histogram Data into Excel
if(getCurrentReplication() == lastReplication){
double intervalWidth = histogramData.getIntervalWidth();
int intervalQty = histogramData.getNumberOfIntervals();
for(int i = 0; i < intervalQty; i++){
traceln(intervalWidth*i + " " + histogramData.getPDF(i));
excelRecords.setCellValue(String.valueOf(intervalWidth*i) + " - " + String.valueOf(intervalWidth*(i+1)), 1, rowIndex, columnIndex);
excelRecords.setCellValue(histogramData.getPDF(i), 1, rowIndex, columnIndex+1);
rowIndex++;
}
}
Example of my intended results:
10 - 80%
20 - 10%
30 - 5%
40 - 2%
50...
60...
Actual results:
0.0 0.0
10.0 0.0
20.0 0.0
30.0 0.998782775272379
40.0 0.0011174522089635631
50.0 9.9772518657461E-5
60.0 0.0
Results after settings initial interval size to 0.1:
0.0 0.9974651710510558
4.0 0.001117719851502934
8.0 9.181270208774101E-4
12.0 2.3951139675062872E-4
16.0 1.5967426450041916E-4
20.0 9.979641531276197E-5
24.0 0.0
How would I go about obtaining my desired results? Am I fundamentally misunderstanding something about the HistogramData object?
Thank you for your help.
The function you are using (getPDF(i)) returns value for the interval in fractions (not in percentages). So, you have to multiply the value by 100 in order to get it as a percentage. As for histogram bars, model analyze the results, specified interval numbers and interval size. After that, it will build the respective number of bars that cover all results. In your case, intervals from 0 to 30 do not provide any results and bars are not presented (PDF here is 0.0).
I have an iPhone camera attachment that captures video at 9FPS and makes it available as individual UIImages. I'm trying to stitch these images together to create a timelapse video of what the camera sees using AVFoundation.
I'm not sure how to properly convert frames and timing to achieve the time compression I want.
For example - I want 1 hour of real life footage to be converted into 1 minute of time lapse. This tells me that I need to capture every 60th frame and append it to timelapse.
Does the code below accomplish 60 seconds to 1 second time lapse conversion? Or do I need to add some more multiplication/division by kRecordingFPS?
#define kRecordingFPS 9
#define kTimelapseCaptureFrameWithMod 60
//frameCount is the number of frames that the camera has output so far
if(frameCount % kTimelapseCaptureFrameWithMod == 0)
{
//...
//convert image and prepare it for recording
[self appendImage:image
atTime:CMTimeMake(currentRecordingFrameNumber++, kRecordingFPS)];
}
Your code will make 1 frame out of 60 go in your film every 1/9s, and increase the frameIndex by one each time.
The result should be a film of [max value for frameCount] / (60 * 9). If you have 32400 frames (1h of film at 9fps), the film will be of {540:9 = 60s}.
Try printing the CMTime using CMTimeShow() at every call to appendImage:atTime: to check.
//at 5 fps, 300 frames recorded per 60 seconds
//to compress 300 frames into 1 second at 5 fps, we need to take every 300/5 = 60th frame
//to compress 300 frames into 1 second at 15 fps, take every 300/15 = 20th frame
//to compress 300 frames into 1 sec at 30 fps, take every 300/30 = 10th frame
#define kReceivedFPS 9
#define kStoreFPS 9
#define kSecondsPerSecondCompression 60
#define kTimelapseCaptureFrameWithMod (kSecondsPerSecondCompression * kReceivedFPS) / kStoreFPS
I'm attempting to convert MPH into minute miles. I'm currently running code to do this by doing 60 / the miles per hour which gives me the result in minute miles.
For example 60/8mph = 7.5
However the answer I get I need to convert into minutes and seconds so that I would have 7 minutes 30 seconds. Is there a way I can get the numbers after the decimal point so I can multiply it by 60 to convert it to seconds, then add it back to the minutes.
You can use remainder,
double remainder = fmod(a_double, another_double);
should include <math.h>
Well, I don't know whether there is an existing class that handles this, but to answer your specific question, the fractional part of the decimal (mantissa?) would be:
((60 % 8) / 8.0f)
You can multiply that by 60.
Do it in seconds...
3600/8 = 450
450/60 = 7 remainder 30
= 7:30
It's pretty simple, you're on the right path actually.
What you need to do is:
Get Minutes
Get Seconds
Convert seconds from int to real time (0.5 to 30, etc..)
Add seconds to minutes
Get minutes by casting it to an Integer:
int minutes = 60/8;
Get seconds by using the remainder:
float seconds = 60%8;
Convert seconds to real time:
int realSeconds = seconds * 60;
Now get result back by adding both:
int totalSeconds = minuts + realSeconds;
Here's a little function that does it (typed directly to browser, probably won't compile)
#include <math.h>
int getMinuteMiles(float mph){
int minutes = 60/mph;
double seconds = fmod(60, mph);
int realSeconds = seconds * 60;
return minutes+realSeconds;
}
I am just multiplying two very big value in ios.
value 1 999999999999
value 2 99999
I am using the data type as double long i.e long long and this works for only too big values but not for small values like 10*23 something like that i get different answers example
10.0*111.5 actual value in calculator is 1115 but i wat i get is 1110
please help me and i also want to roundof my answer to 3places like %.3f
This is probably what you are doing
long long left = 111.5; //Not good! Will truncate to 111
long long right = 10.0; //10
long long result = left * right; //111 * 10 = 1110
This is what you should do
double left = 111.5;
double right = 10.0;
double result = left * right; //111.5 * 10.0 = 1115.0
If for some reason double is not enough you can go for long double.
I have this line in one of my scenes:
[self schedule:#selector(storeValue:) interval:1.0/30.0];
storeValue is very basic and fast. It just stores the position of a layer on an NSMutableArray. I need this storeValue to be called in as much precise as possible timings, but after making some measurements, these are the intervals measured between each storeValue call:
interval 0 = 0
interval 1 = 0.049962
interval 2 = 0.033345
interval 3 = 0.033332
interval 4 = 0.049994
interval 5 = 0.050050
interval 6 = 0.049968
interval 7 = 0.033998
interval 8 = 0.049331
interval 9 = 0.050015
interval 10 = 0.049979
interval 11 = 0.049999
interval 12 = 0.033357
interval 13 = 0.033307
interval 14 = 0.049997
interval 15 = 0.033322
interval 16 = 0.050317
interval 17 = 0.049743
interval 18 = 0.049973
interval 19 = 0.033322
interval 20 = 0.050024
interval 21 = 0.049975
interval 22 = 0.049987
interval 23 = 0.033316
interval 24 = 0.050038
interval 25 = 0.050149
interval 26 = 0.049852
interval 27 = 0.049989
interval 28 = 0.050011
So, as you see, the method is called with a variety of intervals instead of always being 0.03333 (1 / 30).
I have tried to remove all code from storeValue to see how frequently storeValue is called and obtained the same irregular timings.
The big question is this: what should I do to improve schedule precision? Should I use NSTimer? GCD any other method of doing a scheduled task? Any suggestions?
thanks.
NOTE: I've discovered now that if I put interval = 0, storeValue will be called every frame, that means 1/60s and the precision is awesome. OK, I can make a logic to call storeValue half of the time but it would be nice to know why schedule is so imprecise and if there is a way to improve it.
When you schedule something, the selector and timer frequency are passed to Cocos2d sharedScheduler. Then sharedDirector calls [[Scheduler sharedScheduler] tick: dt]; on each frame. If your timer passes its threshold the scheduler calls your selector.
So the frequency cannot be more precise than mainloop frequency (max 1/60, min - depending on actual scene complexity). Probably 1/30 passes threshold not exactly on each 2nd frame and thats why you have not precise values in log.
I can propose to call your selector on other thread via NSTimer without using Cocos2d scheduler.
iOS isn't a Real-time operating system and thus you can never be guaranteed that your scheduled callback/NSTimer/etc. will ever occur at precisely 1/30 of a second. This precision will always vary based on what else the OS is handling.
What you can do, however, is use the actual time passed between each callback to account for this lack of consistency.