I'd like to plot 3 functions in gnuplot while one of them has a higher sampling rate. The reason is that with that high sampling rate, dashed lines look somewhat compressed and become less distinguishable from each other.
The function with the high sampling rate should be plotted with a solid line, the other 2 with dashed lines. Here's a working example:
set term postscript dashed
set out 'test1.ps'
iu = {0.,1.}
kmax = 1.e1
lami = 1.e-2
lamf = 1.e2
lmax = lamf
tau = 5.
fun(x) = (exp(-2. * iu * x * pi * kmax) * (-1. + exp(2. * iu * x * pi * (1. + kmax)))**2 * (atan(lamf / (2. * x * pi)) - atan(lami / (2. * x * pi)))) / (2. * (-1. + exp(2. * iu * x * pi))**2 * x * pi * kmax**0 * (lamf - lami))
funSimp(x) = (2. * tau)/(4. * x**2 * pi**2 + tau**2)
funSimpler(x) = atan(lmax / (2. * x * pi)) / (2. * x * pi)
set xr [1e-4:500]
set yr [1e-6:10]
set logscale x
set logscale y
set samples 10000
plot \
fun(x) / 20. t 'f' w l, \
funSimp(x) t 'fs' w l, \
funSimpler(x) / 20. t 'fss' w l
The dashed lines of 'fs' and 'fss' look different from the ones displayed on the legend. I tried to do
set samples 10000
plot \
fun(x) / 20. t 'f' w l
set samples 50
plot \
funSimp(x) t 'fs' w l ls 2, \
funSimpler(x) / 20. t 'fss' w l ls 3
but this doesn't work out, as only the first plot gets printed to the file. replot also didn't help.
gnuplot 4.6.5, Win 7 64
This is a problem with the postscript terminal. It uses relative coordinates when drawing the lines representing function. Since this may give rounding errors, a moveto is issued every 100 points. This interrupts the path, which becomes visible when using dash patterns. The patch in the sources is a one-liner.
As workaround I would suggest you to use the pdfcairo which doesn't have this problems. Then you can convert the pdf to eps if you need that as output format. Or you could use the cairolatex eps terminal.
Thanks, just to add: I'm actually using gnuplottex (http://www.ctan.org/pkg/gnuplottex). So based on your comment, I changed the terminal like that:
\begin{gnuplot}[terminal=cairolatex,terminaloptions={monochrome dashed dl 3.0 lw 1.0 rounded size 9cm,7cm}]
With this choice and the epstopdf package included beforehand, one can produce gnuplot figures directly with pdfLaTeX and even circumventing the problem with the dashes.
The only thing which I can't do at the moment is to crop the output, like one can do it with dvips "xyz.dvi" -E.
Related
I'm using Three.js and Cannon.js.
Also, I'm trying to reproduce this object (the multiball one).
Basically, the ball goes from its origin to the pressure point and stops, or rotates around the pressure point (this is called mass-spring).
For the moment I was able to set the direction of the ball via velocity but the ball doesn't stop at the pressure point and the more distance there are the higher the velocity is (I need constant velocity).
I've asked the question on Github and someone told me to have a look at this example. The only problem is that it only rotates around a planet where I'm searching how to move a ball to a certain point which doesn't sound to be the same. Any help is greatly appreciated
Maybe you need a physics model like this one:
friction model
m = 2 (it could be also m = 1 or m = 3 or whatever looks good)
coefficients:
cf = coefficient of friction
cs = coefficient of spring
Dynamics / update of position and velocity with time-increment dt
x_cursor = x coordinate of cursor's position
y_cursor = y coordinate of cursor's position
x = x + dt * v_x
y = y + dt * v_y
v_norm = sqrt(v_x^2 + v_y^2)^(m-1)
v_x = v_x - dt * cf * v_norm * v_x - dt * cs * ( x - x_cursor )
v_y = v_y - dt * cf * v_norm * v_y - dt * cs * ( y - y_cursor )
Well, I used the search to find the answer to my question, but it didn't get the result I was looking for, so I'll try asking it here:
If I know the formula for mixing colors:
resultColorRGB = [round(firstColorR * alpha + secondColorR * (1 - alpha))], [round(firstColorG * alpha + secondColorG * (1 - alpha))], [round(firstColorB * alpha + secondColorB * (1 - alpha))]
where alpha ∈ [0..1].
Then how do I find the second color if I know the first color and the color of the result?
For example:
round(35 * alpha + 255 * (1 - alpha)) = 204, round(alpha * 15 + 0 * (1 - alpha)) = 3, round(alpha * 0 + 153 * (1 - alpha)) = 118, alpha = 0.23
I can't use a method for solving a system of linear equations, for two reasons (as I understand it): alpha is not an integer, and the result is calculated by rounding.
But I am sure that there is some way to estimate the approximate calculation, without using iteration.
If all the values were exact, then you have the equation aA+(1-a)B=C, where A and B are your two input colours, a is alpha, and C is the output colour. Each of A, B and C is a triple of red, green, blue, but that makes no difference to the maths; they can each be treated indepdendently.
If you have A and C, and the alpha value a, then you have B=(C-aA)/(1-a). The fact that it's inexact doesn't really matter; you can compute these values exactly, and then round up. You can't get B back exactly since information is lost in the original mixing.
I know there are a lot of questions alrady answered about this. However, mine varies slightly. Whenever we implement the smooth coloring algorithim as I understand it.
mu = 1 + n + math.log2(math.log2(z)) / math.log2(2)
where n is the escape iteration and 2 is the power z is to, and if im not mistaken z is the modulus of the complex number at that escape iteration. We then use this renormalized escape value in our linear interpolation between colors to produce a smoothly banded mandelbrot set. I've seen answers to other questions about this where we run this value through a HSB to RGB conversion, however I still fail to understand how this would provide a smooth gradient of colors and how to implement this in python.
However, whenever I attempted to implement this it produces floating point RGB values, but there isn't an image format that I know of, besides a .tiff file, that would support this, and if we round off to integers we still have unsmooth banding. So how is this supposed to produce a smoothly banded image if we cannot directly use the RGB values it produces? Example code of what I tried below, since I don't undertand fully how to implement this I made an attempt at a solution that somewhat produces smooth banding. This produces a somewhat smoothly banded image between two colors blue for the full set and a progressively whiter color the further we zoom in on the set to the point where at a certain depth everything just appears blurred. Since I'm using tkinter to do this I had to convert the RGB values to hex to be able to draw them to the canvas.
I;m computing the set recursively, and in my other function (not posted below) i am setting the window width and height then iterating over these for the pixels of the tkinter window and computing this recursion in the inner loop.
def linear_interp(self, color_1, color_2, i):
r = (color_1[0] * (1 - i)) + (color_2[0] * i)
g = (color_1[1] * (1 - i)) + (color_2[1] * i)
b = (color_1[2] * (1 - i)) + (color_2[2] * i)
rgb_list = [r, g, b]
for value in rgb_list:
if value > MAX_COLOR:
rgb_list[rgb_list.index(value)] = MAX_COLOR
if value < 0:
rgb_list[rgb_list.index(value)] = abs(value)
return (int(rgb_list[0]), int(rgb_list[1]),
int(rgb_list[2]))
def rgb_to_hex(self, color):
return "#%02x%02x%02x" % color
def mandel(self, x, y, z, iteration):
bmin = 100
bmax = 255
power_z = 2
mod_z = math.sqrt((z.real * z.real) + (z.imag * z.imag))
#If its not in the set or we have reached the maximum depth
if abs(z) >= float(power_z) or iteration == DEPTH:
z = z
if iteration > 255:
factor = (iteration / DEPTH) * 255
else:
factor = iteration
logs = math.log2(math.log2(abs(z) + 1 ) / math.log2(power_z))
r = g = math.floor(factor + 5 - logs)
b = bmin + (bmax - bmin) * r / 255
rgb = (abs(r), abs(g), abs(round(b)))
self.canvas.create_line(x, y, x + 1, y + 1,
fill = self.rgb_to_hex(rgb))
else:
z = (z * z) + self.c
self.mandel(x, y, z, iteration + 1)
return z
The difference between colors #000000, #010000, ..., #FE0000, #FF0000 is so small that you obtain a smooth gradient from black to red. Hence, simply round your values: Suppose your smoothened color values of your smoothness function range from 0 to (excl) 1, then you simply use
(int) (value * 256)
How can I calculate y in this curve ? t is the variable. Origin is (0|0) of course.
the tangents at t=0, t=0,5 and t=1 must be perfectly horizontal (incline = 0)
only basic mathematical operators are available (Java / Actionscript 3)
I have to calculate this a few hundred times each frame in Actionscript 3. So calculation needs good performance. Right now I'm actually failing at correctness of calculation (I'm not a mathematician).
Not sure about performance, but
-0.5 * cos(x * 2pi) + 0.5
AS3:
y = -0.5 * Math.cos(x * 2 * Math.PI) + 0.5;
seems to be the curve you are looking for.
You can view or edit the curve here:
wolfram alfa curve
The function suggested by bjornson (-0.5*cos(x) + 0.5) looks good.
One idea to improve performance is that you at the start of your application create a table of the values of that function at different times.
If you use fix timesteps, then the table is all you'll need. If you have variable time steps, then you can just do linear interpolation between the two closest times to the time you're calculating.
y(t) = 16 * t * t * (t - 1) * (t - 1)
I reckon that one satisfies your requirements
I tried my own way and I came up with a polynomial:
y = 16 * (t - 0.5)^4 - 8 * (t - 0.5)^2 + 1
y = 16 * Math.pow((t - 0.5), 4) - 8 * Math.pow((t - 0.5), 2) + 1;
// forgot to shift the curve 0.5 to the right, corrected
Edit: A description of the GABOR FILTER
% gab2d: **2D Gabor filter**
% The Gabor filter is basically a Gaussian, modulated by a complex sinusoid
% G = gab2d(I,Sx,Sy,f,theta,FUN)
% Input and output arguments ([]'s are optional):
% I (matrix) of size NxM: Input Image of size NxM.
gamma (scalar): The spatial aspect ratio, x to y.
lambda(scalar): The wavelength of the sinusoidal function.
b (scalar): The spatial frequency band-width (in octaves)
theta (scalar): The orientation of the gabor filter.
% phi (scalar): The phase offset. 0 is real part of Gabor filter or
% even-symmetric, pi/2 is imaginary part of Gabor filter or
% odd-symmetric.
% **Note**:
sigma (scalar): The spread of Gabor filter or the standard
% deviation of Gaussian is automatically computed from lambda and b.
% [shape] (strings): Shape for conv2. See help conv2. Default is 'same'.
% % GO (matrix) of size NxM: Output images which was applied Gabor
% filters. This is the magnitude response.
% [GF] (matrix) of size (2Sx+1)x(2Sy+1): Gabor filter.
function [GO, GF] = gab2d(I, gamma, lambda, b, theta, phi, shape)
I=imread('C:\Users\Vinay\Documents\MATLAB\textureflawimages\text9.png');
gamma = 1; b = 1; theta = 0:pi/6:pi-pi/6; phi = 0; shape = 'valid'; lambda=8;
if nargin < 7, shape = 'same'; end;
if isa(I, 'double') ~= 1, I = double(I); end
sigma = (1 / pi) * sqrt(log(2)/2) * (2^b+1) / (2^b-1) * lambda;
Sy = sigma * gamma;
for x = -fix(sigma):fix(sigma)
for y = -fix(Sy):fix(Sy)
xp = x * cos(theta) + y * sin(theta);
yp = y * cos(theta) - x * sin(theta);
GF(fix(Sy)+y+1,fix(sigma)+x+1) = ...
exp(-.5*(xp^2+gamma^2*yp^2)/sigma^2) * cos(2*pi*xp/lambda+phi) ...
; %/ (2*pi*(sigma^2/gamma));
% Normalize if you use different sigma (lambda or b)
end
end
GO = conv2(I, double(GF), shape);
Error:
??? Error using ==> mpower Matrix must be square.
Error in ==> gab2d at 36 GF(fix(Sy)+y+1,fix(sigma)+x+1) = ...
I am somehow not able to rectify this problem ..
Please help
theta is an array. Thus, e.g. xp is an array as well. If you want to square each element of xp, then you need to use element-wise operators, such as .^ for power, or .* for multiplication.
In order to more quickly find out what's wrong, set the debugger to stop whenever there's an error by typing dbstop if error at the command line. This allows you to inspect all variables in the editor by hovering over them with the mouse, and to evaluate small bits of your complicated expression to narrow down your error.