Does a function exist that is similar to rlim in matlab? I need to modify a polar plot for an antenna diagram where the 0 is on the outer rim and all values are negative.
The result should in general (!) look like this picture. Only the scaling (not the ticks) on the radial axes is relevant, though.
Ok, I'll provide an example for the sake of demonstrating what I was on about:
t = 0 : 0.01 : 2 * pi;
r = abs( 2 + 5 * sin( 3 .* t ) .* ( 1 + 2 * pi .* t - t .^ 2 ) );
p = polar( gca, t, r );
set( groot, 'showhiddenhandles', 'on' )
TTicks = [ 0 : 45 : 315 ]; % Note: here, specified in degrees
RTicks = [ 20 : 20 : 100 ]; % Note: 'zero' not included!
set( gca, 'ttick', TTicks );
set( gca, 'rtick', RTicks );
NumTticks = length( TTicks );
NumRticks = length( RTicks ); % will only be correct if zero was excluded above.
PolarGrid = findobj( gca, 'tag', 'polar_grid' );
Handles = get( PolarGrid, 'children' );
NumHandles = length( Handles );
% The children are arranged as follows:
% NumTticks handles: text objects that make up the ttick labels (from last to first)
% NumTticks handles: line objects that make up the ttick gridlines
% NumRticks handles: text objects that make up the rtick labels (from last to first)
% NumRticks handles: line objects that make up the rtick concentric gridlines
% Last handle : A darker line, coinciding with the last rtick gridline, serving as the outline.
% Therefore, to change the rticklabels:
RTickLabelHandles = Handles( NumHandles - NumRticks - [1 : NumRticks] );
RTickLabels = { '', '30db', '20db', '10db', '0' };
for i = 1 : NumRticks, set( RTickLabelHandles(i), 'string', RTickLabels{i} ), end;
But, having said that, if your requirements deviate to such an extent from what the polar function is expected to provide (including a custom 0 angle orientation), then you're right, it's probably better to simply draw all the elements yourself from scratch (including grid circles and custom labels).
Related
What I am trying to do is create something that looks like this,
which I have created by using the Octave pcolor and barh functions using 3 subplots with the subplot x axes scaled to look as if the figure were one plot. However, this approach is unsatisfactory as I cannot zoom or pan across it as I would be able to if it were actually one plot.
How can I plot one background figure using pcolor and then add multiple y axes at different points along the x axis to plot the horizontal histograms using barh?
For some background to this question, I am trying to create what is called a Market Profile chart, i.e. see example here or here.
I have also cross posted this question on the Octave mailing list here.
I have found a way to do what I want. Instead of using the barh function, one can use the fill function instead.
A minimal, reproducible example given below.
## create y and x axes for chart
y_max = max( high_round ) + max_tick_range * tick_size ;
y_min = min( low_round ) - max_tick_range * tick_size ;
y_ax = ( y_min : tick_size : y_max )' ;
end_x_ax_freespace = 5 ;
x_ax = ( 1 : 1 : numel( open ) + end_x_ax_freespace )' ;
colormap( 'viridis' ) ; pcolor( x_ax , y_ax , vp_z' ) ; shading interp ; axis tight ;
## plot the individual volume profiles
hold on ;
scale_factor = 0.18 ;
fill( vp( 1 , : ) .* scale_factor , y_ax' , [99;99;99]./255 ) ;
fill( vp( 2 , : ) .* scale_factor .+ 50 , y_ax' , [99;99;99]./255 ) ;
fill( vp( 3 , : ) .* scale_factor .+ 100 , y_ax' , [99;99;99]./255 ) ;
hold off;
More details on a blog post of mine.
My data file data.dat looks like this:
1e-23 1e-23 1e-27 2e-28
2e-22 4e-23 1e-23 4e-23
3e-21 1e-23 1e-24 6e-23
4e-32 1e-23 1e-25 8e-30
Using gnuplot, I use stats "data.dat" matrix to find minimum and maximum values in the above array (data file); both values are shown zero. I am guessing stats is reading exponentially low values as zero. Is there a way to fix this?
If you execute the command
stats 'data.dat' matrix
the output minimum/maximum reported is indeed:
Minimum: 0.0000 [ 0 3 ]
Maximum: 0.0000 [ 0 2 ]
COG: 0.1157 1.9057
This is due to the strategy Gnuplot uses for formatting the values in the stats output. The relevant function is:
static char*
fmt( char *buf, double val )
{
if ( isnan(val) )
sprintf( buf, "%11s", "undefined");
else if ( fabs(val) < 1e-14 ) //<-- HERE
sprintf( buf, "%11.4f", 0.0 );
else if ( fabs(log10(fabs(val))) < 6 )
sprintf( buf, "%11.4f", val );
else
sprintf( buf, "%11.5e", val );
return buf;
}
this means that if a value in absolute value is smaller than 1E-14, it will show just zero...
To get the raw values, you might use the STATS_min/STATS_max variables:
gnuplot> print STATS_min, STATS_max
4.00000009496891e-32 2.99999990479657e-21
EDIT:
The stats 'filename' matrix seems to behave slightly differently than the "ordinary" stats executed per column:
fname = 'data.dat'
stats fname nooutput
N = STATS_columns
#specify which values to include in the minimum calculation
cond(val) = 1 #(abs(val) > 1E-30)
#process each column individually and determine the global minimum
#if there are no values, set the minimum to +inf
globalMin = real('inf')
do for [i=1:N] {
stats fname using (cond(column(i))?column(i):NaN) nooutput
#due to cond( ), there might not be any records, so one needs to check
if(STATS_records) {
globalMin = (STATS_min < globalMin)?STATS_min:globalMin
}
}
print globalMin
I have a 3d game where I will create an rectangle which is working as screen and the game itself works with vectors to positions. so I will create an rectangle and have only these parameters aviable:
start position ->vector (x,y,z).
Angle(rotation) of object(x,y,z).
size of rectangle.
now also the object need to be roatet to the right side so they are using angels also (x,y,z).
example:
position:-381.968750 -28.653845 -12702.185547
angle: -0.000 90.000 90.000
What I will create is an little bit hard but as idea simple.
I choose 2 complete different positions and angles and will create from the first vector to the second an rectangle.
I can only create an rectangle with the start point and angle.
and I can set the size so (x,y)
So I will now insert 2 positions(vectors) with 2 different angles
The rectangle will have the middle value between the first and second angle so like (90 and 0) -> 45
And the rectangle will start at the start vector and will end with his own size so I don't have a chance to use the end vector directly.
Legendary on photo:
Green=>start and end positions(vectors).
red => the marked zone.
Blue => how I will have the rectangle.
aem_point = vgui.Create( "AEM.Main.Panel" )
if IsValid(aem_point) then
aem_point:SetSize( 2,2 ) -- <-the size that i can set
aem_point:SetPos( 0, 0 )
aem_ph = vgui.Create( "DHTML", aem_point )
aem_ph:SetSize( aem_point:GetSize() )
aem_ph:SetPos(aem_point:GetPos())
aem_ph:SetVisible( true )
aem_ph:SetHTML([[
<html>
<body style="margin:0px;padding:0px;font-size:20px;color:red;border-style: solid;border-color: #ff0000;background-color:rgba(255,0,0,0.1);">
</body>
</html>
]] )
end
hook.Add( "PostDrawOpaqueRenderables", "DrawSample3D2DFrame" .. math.random(), function()
if first and dat_finish then
vgui.Start3D2D( input_position, input_angle, 1 ) -- <-and position&vec
aem_point:Paint3D2D()
vgui.End3D2D()
end
end )
Oh so you want to create a 3d2d plane from 2 vector positions?
Vec1 = A
Vec2 = B
input_position = ( Vec1 + Vec2 ) / 2
A problem you will run into is you need 3 points to generate a plane, so while you can get the position of the screen to get the angle of it you will need another point.
If these screens of yours are staticly set, as in you put their position into the lua code manually and dont intend to have it move or anything, just manually putting in the angle is by far the most simple approch.
As you can see, both of these planes are on the same two points, but they have diffrent angles.
I wrote the demo in expression 2, this should make it clear as to how this works, if you have any other questions just ask.
A = entity(73):pos()
B = entity(83):pos()
if(first())
{
holoCreate(1)
holoCreate(2)
}
holoPos(1,(A+B)/2)
holoScaleUnits(1,vec( abs(B:y() - A:y()) , 1 , abs(sqrt( ( B:z() - A:z() ) ^ 2 + ( B:x() - A:x() ) ^ 2 ))))
holoAng(1,ang(0,90,45))
holoPos(2,(A+B)/2)
holoScaleUnits(2,vec( abs(sqrt( ( B:x() - A:x() ) ^ 2 + ( B:y() - A:y() ) ^ 2 )) , 1 , abs(B:z()-A:z())))
holoAng(2,ang(0,45,0))
First off, let me warn you that my Maths knowledge is fairly limited (hence my coming here to ask about this).
It's a silly example, but what I essentially want is to have a variable number of rows, and be able to set a maximum value, then for each progressive row decrease that value until half way at which point start increasing the value again back up to the maximum by the final row.
To illustrate this... Given that: maxValue = 20, and rows = 5, I need to be able to get to the following values for the row values (yes, even the 0):
row 1: 20
row 2: 10
row 3: 0
row 4: 10
row 5: 20
There are limitations though because I'm trying to do this in Compass which uses SASS. See here for the available operations, but to give you the gist of it, only basic operations are available.
I'm able to loop through the rows, so just need the calculation that will work for each individual row in the series. This is the kind of loop I'm able to use:
$maxValue:20;
$rows:5;
#for $i from 1 through $rows {
// calculation here.
}
I haven't really worked with SASS before, but try something like this using a basic if and the floor function, not sure if will work
// set various variables
$maxValue:20;
$rows:5;
// get row number before middle row, this instance it will be 2
$middleRow = floor( $maxValue / $rows )
// get increment amount, this instance should be 10
$decreaseValue = ( max / floor( rows / 2) )
#for $i from 0 through $rows - 1 {
#if $i <= $middleRow {
( $maxValue- ( $decreaseValue * $i ) )
}
#else{
// times by -1 to make positive value
( $maxValue - ( $decreaseValue * -$i ) ) * -1
}
}
I have tested the above in js ( with relative syntax ) and it yielded the required results ( jsBin example ). Hope this helps
I am currently working on a simple car simulation on a plane in DirectX. I am having problems on orienting the car on the plane .
what i am doing is this...
D3DXMATRIX planeMat //matrix of the plane on which car is currently situated.
...
//calculating car rotation matrix (on XZ plane )
D3DXMATRIX carRot;
D3DXMatrixRotationY( &carRot , yaw );
//car up will same as plane
D3DXVECTOR3 carUp = D3DXVECTOR3( planeMat._12 , planeMat._22 , planeMat._32 );
//car lookat vector
D3DXVECTOR3 carLookat = D3DXVECTOR3( carRot._13 , carRot._23 , carRot._33 );
// calculating right vector
D3DXVec3Cross( &carRight , &carLookAt , &carUp );
D3DXVec3Normalize( &carRight , &carRight );
//calculating new lookat
D3DXVec3Cross( &carLookAt , &carRight , &carUp );
D3DXVec3Normalize( &carLookAt , &carLookAt );
//car matrix
D3DXMATRIX carMat; D3DXMatrixIdentity( &carMat );
carMat._11 = carRight.x ;carMat._21 = carRight.y ;carMat._31 = carRight.z ;
carMat._12 = carUp.x ;carMat._22 = carUp.y ;carMat._32 = carUp.z ;
carMat._13 = carLookAt.x ;carMat._23 = carLookAt.y ;carMat._33 = carLookAt.z ;
carMat._41 = carPos.x ;carMat._42 = carPos.y ;carMat._43 = carPos.z ;
I can't get car's rotation correct.please help me.
The way you are setting & using components in your matrix doesn't look correct. For instance, in carMat the 3 basis vectors have the 2nd digit of the component constant but in the last one (carPos), the 1st digit of the component is constant. It's either one way or the other for all 4 rows/columns of the matrix.
I believe the way you are setting the car's position (last row/column) is the correct way and the way you are doing the up, right, & lookat are incorrect. So, for instance, it should probably be like this:
D3DXMATRIX carMat; D3DXMatrixIdentity( &carMat );
carMat._11 = carRight.x ;carMat._12 = carRight.y ;carMat._13 = carRight.z ;//11, 12, 13 instead of 11, 21, 31
carMat._21 = carUp.x ;carMat._22 = carUp.y ;carMat._23 = carUp.z ;
carMat._31 = carLookAt.x ;carMat._32 = carLookAt.y ;carMat._33 = carLookAt.z ;
carMat._41 = carPos.x ;carMat._42 = carPos.y ;carMat._43 = carPos.z ;
Also, the way you populate the vectors carUp and carLookAt fom the components of planeMat & carRot suffers from the same issue.