I set my Y axis max as 1, min as 0 and tick as 0.1. The graph displays as 0, 0.1, 0.2, 0.30000000000004, 0.4 etc. What I mean here is that it does not display 0.3 properly and also some other values in a the similar style. But once I set the tick to more than 0.2, it will display everything properly. So anyone else have experienced the same problem or just myself doing something wrong?
Thanks.
I actually figured it out myself.
In the jquery.svggraph.js file which comes with the plugin, line 493, it adds the tick value to the previous value, so in my case the previous value was 0.2 when it adds 0.1 to it, the result becomes 0.3000000004. I don't know why it does that, maybe it stores the value as float number. What I did to solve this is to add major = Math.round( major * 100 ) / 100 under line 498. Hope this might help someone else who had same problem as I did.
Related
I hope this is the right place to ask this question.
I have a curve that I'd like to fit, but I don't know exactly what kind of fitting would be appropriate.
The curve is the following:
y is converging towards 1 when x grows to infinity.
I tried something like f : x -> 1-k*exp(-l*x) but the result is far from convincing.
I have no clue where to start here, anyone has an idea?
Here are the data used to build the above figure. it takes me 1.5 minutes to compute one point of my function.
x = [0.04, 0.08, 0.12, 0.16, 0.2 , 0.24, 0.28, 0.32, 0.36, 0.4 ]
y = [0.71368682, 0.79734766, 0.83832184, 0.86394632, 0.8818312 ,
0.89515722, 0.90553446, 0.91387899, 0.92075551, 0.92653329]
Thanks a lot!
What make you assume that " y is converging towards 1 when x grows to infinity" ?
This doesn't match to the data. Or the data is in a too small range far from large x. Or the kind of function thay you choose might be not convenient.
For example assuming another exponential function :
Using the regression method shown pages 16-17 in : https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales the numerical calculus and result is :
If the limit at x infinit is definitively 1 you should look for another kind of function. Without clue from the origin of data one have to proceed by trial and error.
I'd like to see later drawn object blocks previously drawn objects if they have the same z value. It is like z-index in css. How to achieve this?
There is a "CullFaceFrontBack" constant here, but where do I set this constant? How do I know if it is in effect?
THREE.CullFaceNone
THREE.CullFaceBack
THREE.CullFaceFront
THREE.CullFaceFrontBack
Here is the code I used to generate the offset position:
for(let i = 0; i < SQUARE_COUNT; i++ ) {
offsets.push( Math.random() - 0.5, Math.random() - 0.5, 0); // z is same for all offsets
colors.push( Math.random(), Math.random(), Math.random(), Math.random() );
}
The reason I am trying to cull is because my render is like this, it is basically 1000 square rendered at the same Z axis, x and y are random. They all keep flashing when rotating, no rotating no flashing. I think the problem is GPU is trying to rendering one on top of another and trying to blend and re-render. But I could be wrong, please correct me.
No, "cull" means to render only polygons that are facing a certain direction (usually, away). It doesn't have anything to do with other objects being in front of it.
You said you want squares added later in the loop to be on top visually. Since GPU-based rendering usually only cares about depth, not order, you'd have to add a z value to tell it to render them in front of the other squares. To do that, specify the z value as the third parameter where you have zero, i.e.
offsets.push( Math.random() - 0.5, Math.random() - 0.5, i * 0.01);
The constant 0.01 might be something you have to experiment with.
I think those constants are now obsolete, I get this error when trying to set them:
THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set
Material.shadowSide instead.
Try this:
const mat = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide } );
nb: you'll need a light if you use Phong or Lambert
By default, stretch-to-fill is on. So
pixels = ones(100,100)
image(pixels);
colormap([0 0 0; 1 1 1]);
produces
Forcing the axes to be of the same scale, this
pixels = ones(100,100)
image(pixels);
colormap([0 0 0; 1 1 1]);
axis equal;
produces
Obviously, stretch-to-fill is overridden by axis equal. What to do to make them co-exist?
I think you are looking for this call:
figure(1)
image(pixels)
colormap(clr)
axis image % <-- this call
Here is a table of the axes properties manipulated by the various axis modes:
You can also do something similar using the imshow function, which acts as a higher-level wrapper to image/imagesc:
figure(2)
imshow(pixels, clr, 'InitialMag','fit', 'Border','loose')
axis on
The problem is, your axis limits reflect the old size. Maybe there is a generic way to solve it, but setting the limits manually solves it:
xlim([1,100]);ylim([1,100])
I guess this is a very basic question.
I have a graph which I created in MATLAB. This is a graph of Power (y-axis) versus Frequency (x-axis).
The range of my x-axis is from 0 to 1000. Now here is my problem. I want to draw a line from specific points on the x-axis to the graph. For example, for points 40, 400, 950.
By using set(gca, 'XTick', [40 400 950]); I am able to mark these particular points. But I want to make it more visible by drawing straight vertical lines from these points.
Any help will be greatly appreciated. Thank you.
Use plot with endpoints with the same x value and different y values. (and don't forget to use myaa to beautify the output).
x = 0:0.1:2*pi;
y = sin(x);
plot(x,y);
hold on;
plot([0.6 0.6], [-1 1], 'Color', [0.7 0.7 0.7], 'LineWidth', 2);
plot([3.6 3.6], [-1 1], 'Color', [0.7 0.7 0.7], 'LineWidth', 2);
If you do this often I would recommend you a great submission from the FileExchange:
hline and vline
Just do:
vline([40 400 950])
Read the function documentation, if you want the line to have different properties than default.
I typically do this using something like this (is powers is a row vector).
powers = randn(1,1000)+40;
plot([1;1]*[40 400 950], [[0 0 0]; [powers([40 400 950])]],'k-')
I'm trying to add a fade effect to my form by manually changing the opacity of the form but I'm having some trouble calculating the correct value to increment by the Opacity value of the form.
I know I could use the AnimateWindow API but it's showing some unexpected behavior and I'd rather do it manually anyways as to avoid any p/invoke so I could use it in Mono later on.
My application supports speeds ranging from 1 to 10. And I've manually calculated that for a speed of 1 (slowest) I should increment the opacity by 0.005 and for a speed of 10 (fastest) I should increment by 0.1. As for the speeds between 1 and 10, I used the following expression to calculate the correct value:
double opSpeed = (((0.1 - 0.005) * (10 - X)) / (1 - 10)) + 0.1; // X = [1, 10]
I though this could give me a linear value and that that would be OK. However, for X equal 4 and above, it's already too fast. More than it should be. I mean, speeds between 7, and 10, I barely see a difference and the animation speed with these values should be a little more spaced
Note that I still want the fastest increment to be 0.1 and the slowest 0.005. But I need all the others to be linear between them.
What I'm doing wrong?
It actually makes sense why it works like this, for instance, for a fixed interval between increments, say a few milliseconds, and with the equation above, if X = 10, then opSpeed = 0.1 and if X = 5, then opSpeed = 0.47. If we think about this, a value of 0.1 will loop 10 times and a value of 0.47 will loop just the double. For such a small interval of just a few milliseconds, the difference between these values is not that much as to differentiate speeds from 5 to 10.
I think what you want is:
0.005 + ((0.1-0.005)/9)*(X-1)
for X ranging from 1-10
This gives a linear scale corresponding to 0.005 when X = 1 and 0.1 when X = 10
After the comments below, I'm also including my answer fit for a geometric series instead of a linear scale.
0.005 * (20^((X-1)/9)))
Results in a geometric variation corresponding to 0.005 when X = 1 and 0.1 when X = 10
After much more discussion, as seen in the comments below, the updates are as follows.
#Nazgulled found the following relation between my geometric series and the manual values he actually needed to ensure smooth fade animation.
The relationship was as follows:
Which means a geometric/exponential series is the way to go.
After my hours of trying to come up with the appropriate curve fitting to the right hand side graph and derive a proper equation, #Nazgulled informed me that Wolfram|Alpha does that. Seriously amazing. :)
Wolfram Alpha link
He should have what he wants now, barring very high error from the equation above.
Your problem stems from the fact that the human eye is not linear in its response; to be precise, the eye does not register the difference between a luminosity of 0.05 to 0.10 to be the same as the luminosity difference between 0.80 and 0.85. The whole topic is complicated; you may want to search for the phrase "gamma correction" for some additional information. In general, you'll probably want to find an equation which effectively "gamma corrects" for human ocular response, and use that as your fading function.
It's not really an answer, but I'll just point out that everyone who's posted so far, including the original question, are all posting the same equation. So with four independent derivations, maybe we should assume that the equation was probably correct.
I did the algebra, but here's the code to verify (in Python, btw, with offsets added to separate the curves:
from pylab import *
X = arange(1, 10, .1)
opSpeed0 = (((0.1 - 0.005) * (10 - X)) / (1 - 10)) + 0.1 # original
opSpeed1 = 0.005 + ((0.1-0.005)/9)*(X-1) # Suvesh
opSpeed2 = 0.005*((10-X)/9.) + 0.1*(X-1)/9. # duffymo
a = (0.1 - 0.005) / 9 #= 0.010555555555... # Roger
b = 0.005 - a #= -0.00555555555...
opSpeed3 = a*X+b
nonlinear01 = 0.005*2**((2*(-1 + X))/9.)*5**((-1 + X)/9.)
plot(X, opSpeed0)
plot(X, opSpeed1+.001)
plot(X, opSpeed2+.002)
plot(X, opSpeed3+.003)
plot(X, nonlinear01)
show()
Also, at Nazgulled's request, I've included the non-linear curve suggested by Suvesh (which also, btw, looks quite alot like a gamma correction curve, as suggested by McWafflestix). The Suvesh's nonlinear equation is in the code as nonlinear01.
Here's how I'd program that linear relationship. But first I'd like to make clear what I think you're doing.
You want the rate of change in opacity to be a linear function of speed:
o(v) = o1*N1(v) + o2*N2(v) so that 0 <= v <=1 and o(v1) = o1 and o(v2) = o2.
If we choose N1(v) to equal 1-v and N2(v) = v we end up with what you want:
o(v) = o1*(1-v) + o2*v
So, plugging in your values:
v = (u-1)/(10-1) = (u-1)/9
o1 = 0.005 and o2 = 0.1
So the function should look like this:
o(u) = 0.005*{1-(u-1)/9} + 0.1*(u-1)/9
o(u) = 0.005*{(9-u+1)/9} + 0.1*(u-1)/9
o(u) = 0.005*{(10-u)/9} + 0.1(u-1)/9
You can simplify this until you get a simple formula for o(u) where 1 <= u <= 10. Should work fine.
If I understand what you're after, you want the equation of a line which passes through these two points in the plane: (1, 0.005) and (10, 0.1). The general equation for such a line (as long as it is not vertical) is y = ax+b. Plug the two points into this equation and solve the resulting set of two linear equations to get
a = (0.1 - 0.005) / 9 = 0.010555555555...
b = 0.005 - a = -0.00555555555...
Then, for each integer x = 1, 2, 3, ..., 10, plug x into y = ax+b to compute y, the value you want.