I don't understand scaling in svglib - svg

anyone knows in what consist scale in svglib ? whats the measure ? I don't get what correspond the 10 in this example, is it pixel, inch ... ?
Thank you for your help
drawing = svg2rlg(StringIO(textwrap.dedent('''
{}'''.format(xml_svg))))
# scale https://github.com/deeplook/svglib/issues/207
sx = sy = 10
drawing.width, drawing.height = drawing.minWidth() * sx, drawing.height * sy
drawing.scale(sx, sy)

Related

Select a screen-space point uniformly at random

I am working on implementing Alchemy AO and reading through their paper and they mention to sample each point by: considering a
Disk of radius r and center C that is parallel to the image plane,
select a screen-space point Q uniformly at random on it's project, and
then read a depth or position buffer to find the camera-space scene
point P = (xp, yp, z(Q)) on that ray.
I am wondering how you would go about selecting a screen-space point in the manor? I have made an attempt below but since my result appears quite incorrect, I think it's the wrong approach.
vec3 Position = depthToPosition(uvCoords);
int turns = 16;
float screen_radius = (sampleRadius * 100.0 / Position.z); //ball around the point
const float disk = (2.0 * PI) / turns;
ivec2 px = ivec2(gl_FragCoord.xy);
float phi = (30u * px.x ^ px.y + 10u * px.x * px.y); //per pixel hash for randdom rotation angle at a pixel
for (int i = 0; i < samples; ++i)
{
float theta = disk * float(i+1) + phi;
vec2 samplepoint = vec2(cos(theta), sin(theta));
}

FiPy Setting outflow condition the correct way

I need some help with a quiete simple problem in FiPy. My goal is to simulate a fluid flowing through a concrete block while phase change.
But first of all I tried to do a simple 1D simulation assumed a fluid massflow and a constant wall temperature without any phase change.
from fipy import *
from fipy.meshes import CylindricalGrid2D, Grid1D
import matplotlib.pyplot as plt
import numpy as np
#%%
L = 1.5 #length transfer surface
bS = 0.75 #wide
AV = L * bS #transfer surface
tS0 = 350. #tWall
rhoWF = 880. #density fluid
mWF = 0.036 #mass flow
u = 5e-4 #Fluid speed
hWF = mWF / AV / rhoWF / u #height "fluid block"
nx = 50
VWF = hWF * L * bS/nx #fluid volumen
lambdaWF = 0.6 # thermal conductivity
alpha = 500. #heat transfer coefficient
tWF0 = 371.
mesh = Grid1D(dx=L/nx, nx=nx)
tWF = CellVariable(name="Fluid",
mesh=mesh,
value= tWF0,
hasOld=True)
tS = CellVariable(name="storage",
mesh=mesh,
value=tS0,
hasOld=True)
sourceWF=CellVariable(name="source Fluid", #Variable der Konvektion
mesh=mesh,
value=0.)
cvrho = CellVariable(name = 'cprho',#Fluid
mesh = mesh,
value = rhoWF * 4215.2,
hasOld = True)
tWF.constrain(tWF0, mesh.facesLeft()) #constant inlet temperature
t = 6*3600. #time
timeStepDuration = 1e2
#outflow boundary condition
outlet = mesh.facesRight
ConvCoeff = FaceVariable(mesh,value=u,rank=1)
exteriorCoeff = FaceVariable(mesh,value=0.,rank=1)
exteriorCoeff.setValue(value=ConvCoeff, where=outlet)
ConvCoeff.setValue(0., where=outlet)
residual1 = 1.
elapsedTime = 0.
tWFall = np.zeros(nx)[None,:]
while elapsedTime < t:
tWF.updateOld()
it = 0 #iterations
while residual1> 1e-2:
sourceWF.value = - AV / nx * alpha*(tWF - tS)/ cvrho / VWF #this will be a variable convection source
eq1 = HybridConvectionTerm(coeff=ConvCoeff) + TransientTerm(coeff=1.) == \
+ sourceWF\
- ImplicitSourceTerm(exteriorCoeff.divergence) \
#+ DiffusionTerm(coeff= lambdaWF / cvrho) #not necessary(?)
residual1 = eq1.sweep(dt = timeStepDuration, var = tWF)
print('res1: ' + str(residual1) )
it += 1
if it > 10:
raise ValueError (r'MaxIter reached')
elapsedTime += timeStepDuration ; print('t= ' + str(round(elapsedTime,2)))
residual1 = 1.
tWFall = np.r_[tWFall, tWF.value[None,:]] #value collection
#%% outlet fluid temperature and storage temperature
plt.plot(np.linspace(0,t/3600.,int(t/timeStepDuration)), tWFall[1:,-1], label=r'$\vartheta_{WF}$')
plt.legend()
I would expect a constant fluid outlet temperature because of the constant wall temperature and constant fluid inlet temperature. I have not defined the wall temperature as a boundary condition because some day I would like to analyse heat conduction and variable temperature gradients too. Running my mwe you can see that the fluid temperature at the outlet declines.
Could someone please help at this case?
Thanks in advance!
I changed the script around and it seem to give a constant temperature of 371.0. See this link.
The sourceWF term has been removed. I was unsure what this was for, but I think it would take time for the wall temperature to adjust to this.
The equation declaration has been moved outside the loop. This is the correct way to use FiPy, but shouldn't impact the results in this case.

Drawing a circle with a specific start point (from degree view)

the drawing algorithm which I currently use:
a_max = Pi*2 (float)(num_segments - 1.0f)/(float)num_segments;
for (unsigned int i = 0; i<=num_segments;i++)
{
const float a = (float)i / (float)num_segments * a_max;
SetPixel(centre.x + cos(a) *radius, centre.y +sin(a) *radius);
}
Works fine, but it starts drawing at (centre.x+radius, centre.y). I would like to have it to start at the top , because I want to draw a compass and zero degree is at the top, not on the right, so that I don't have to make a hacky solution.
Try rotating 90 degrees to the left before you start drawing, this should solve it for you.
A compass not only starts at "north" instead of "east" but also goes clockwise instead of counter-clockwise.
For this case, just swap sin(a) and cos(a):
x = centre.x + sin(a) * radius
y = centre.y + cos(a) * radius

How to make 161 meter / 528ft circles on with OSMDROID?

I'm using OsmDroid on OpenStreetMaps and can make markers and polylines, but I can't find any examples on how I'd make 161m/528ft circles around a marker.
a) How do I make circles?
b) How do I make them 161m/528ft in size?
Thanks to MKer, I got an idea on how to solve the problem and made this piece of code, which works:
oPolygon = new org.osmdroid.bonuspack.overlays.Polygon(this);
final double radius = 161;
ArrayList<GeoPoint> circlePoints = new ArrayList<GeoPoint>();
for (float f = 0; f < 360; f += 1){
circlePoints.add(new GeoPoint(latitude , longitude ).destinationPoint(radius, f));
}
oPolygon.setPoints(circlePoints);
oMap.getOverlays().add(oPolygon);`
I know this can be optimized. I'm drawing 360 points, no matter what the zoom is!
If you want a "graphical" circle, then you can implement easily your own CircleOverlay, using the DirectedLocationOverlay as a very good starting point.
If you want a "geographical" circle (than will appear more or less as an ellipse), then you can use the OSMBonusPack Polygon, that you will define with this array of GeoPoints:
ArrayList<GeoPoint> circlePoints = new ArrayList<GeoPoint>();
iSteps = (radius * 40000)^2;
fStepSize = M_2_PI/iSteps;
for (double f = 0; f < M_2_PI; f += fStepSize){
circlePoints.add(new GeoPoint(centerLat + radius*sin(f), centerLon + radius*cos(f)));
}
(warning: I translated from a Nominatim piece of code in PHP, without testing)

Spectrogram - Calculating is wrong

Ok, so basically, I am implementing the following algorithm:
1) Slice signal of size 256 with an overlap of 128
2) Multiply each chunk with the Hanning window
3) Get DFT
4) Compute the abs value sqrt(re*re+im*im)
Plotting these values, as a imshow I get the following result:
This looks ok, it's clearly showing some difference, i.e. the spike where the signal has most amplitude shows. However, in Python I get this result:
I know that I'm doing something right, but, also doing something wrong. I just can't seem to find out where which is making me not think I have done it correctly.
Any rough ideas to where I could be going wrong here? I mean, is plotting the abs value the right way here or not?
Thanks
EDIT:
Result after clamping..
UPDATE:
Code:
for(unsigned j=0; (j < stft_temp[i].size()/2); j++)
{
double v = 10 * log10(stft_temp[i][j].re * stft_temp[i][j].re + stft_temp[i][j].im * stft_temp[i][j].im);
double pixe = 1.5 * (v + 100);
STFT[i][j] = (int) pixe;
}
Typically you might want to use a log magnitude and then scale to the required range, which would usually be 0..255. In pseudo-code:
mag_dB = 10 * log10(re * re + im * im); // get log magnitude (dB)
pixel_intensity = 1.5 * (mag_dB + 100); // offset and scale
pixel_intensity = min(pixel_intensity, 255); // clamp to 0..255
pixel_intensity = max(pixel_intensity, 0);

Resources