intersection() in OpenSCAD - openscad

I have problems with intersection() in OpenSCAD. Here is the code
intersection(){
rotate_extrude($fn=200)
translate([30, 0, 0])
circle(r=5);
translate([0,0,-50])
cube([100,100,100]);
};
It looks good
until you chance the point of view
It is not what I expected. How can I fix it?

if you only compile your code, the view might be damaged. Compile and render and you see your correct 3D-object. To verify export as stl, then import the stl-file in a new document and examine it

You probably should set the convexity parameter in the extrusion, otherwise the renderer might assuming the object is convex, leading to the rendering errors in your screen shot.
For a torus, convexity should be set to at least 4, because a straight line can intersect it as many as four times. I believe the torus example in the docs sets the convexity to 10, which is overkill, but there doesn't seem to be a problem with erring in that direction.

Related

Processing sketches in eclipse not working as expected

In eclipse(or VS code) the sketch window is larger than what is defined in the sketch, in the size() function. For example, even though in the code it is size(800,600); the window of the sketch is 1000 X 750, for some reason. Is there a way to fix this. Also the shapes have jagged edges(perhaps because of this resizing).Is their a way to fix this?
I believe this is because Processing is only rendering a quarter of the pixels created for the canvas. This is probably because the pixel density is set to 1. Simply run: pixelDensity(2); and this should fix the problem. If you don't know what the pixel density of your monitor is, run: pixelDensity(displayDensity());
Here's some documentation:
https://processing.org/reference/pixelDensity_.html

Which color-key to use in a heat-map with a small range of values?

My data covers a small range, but I still like to make the small differences between the data points visible in a heat-map. What color-key is best to maximize color intensity (and not generating a greyish map) and how to set the range in pheatmap?
You didn't give enough information to give you an exact code example for your sample data, but something like the below is a way to get at the problem. In terms of what actual colours you want to use, I recommend you play around with it to see what looks best, I have just subbed in red and blue as a proxy.
pheatmap(yourdata, color = colorRampPalette(c("red", "blue"))(length(-12:12)),breaks=c(-12:12))
The length() is setting the range while the breaks=c(x:x) tells it where to make breaks. So let's say you wanted breaks every 0.2 from 0 to 1, you would modify it to be:
breaks=c(0,0.2,0.4,0.6,0.8,1.0)
You can play around with the break gradients to get something that works for your dataset.
This is my first attempt at answering a question on here, please let me know if something above does't work for you, or if you are confused by what I've written.

How to prevent the fill command in MATLAB from creating boxes without "corners"

I am currently using the fill command in MATLAB to create a graph of boxes that were created using the 'fill' command (the actual code is based off this StackOverflow Question.
My issue is that the boxes that I create do not have "corners." I am attaching a PNG that illustrates the issue. Note that you have to look a little carefully since the image was heavily rendered, though in this example my arrows also look weird since they don't have edges either)
I am wondering if anyone has an idea of what might be going wrong? The boxes appear this way immediately after I use the fill command, which has the following structure:
fill(X,Y,MyFaceColor,'FaceAlpha',0.5,'EdgeColor', MyEdgeColor,'LineStyle','','LineWidth',box_line_width,'EdgeAlpha',1)
The function fill appears to leave space for corner markers if they are not explicitly defined. Hence, calling fill with the marker property will solve your problem. However, since markers and linewidths seem to work on different scales, you will have to play around with the marker size to get smooth edges.
Example:
fill(X,Y,'r','FaceAlpha',0.5,'EdgeColor', 'k',...
'LineWidth', 5,'EdgeAlpha',1 , 'marker', '.', 'markersize', 15)

Where did the drawBackground hook go? Or why is my last point the wrong color

To try and solve this problem, I started looking into writing a plugin for flot to do what I needed. It looked surprisingly straight-forward, but I have run into a minor snag. I First used the draw hook to draw my axis (note: I'm aware this code needs some error checking to make sure the origin isn't off the chart)
function draw(plot, ctx) {
var offset = plot.getPlotOffset();
var origin = plot.pointOffset({ x: 0, y: 0 });
ctx.moveTo(offset.left, origin.top);
ctx.lineTo(plot.width() + offset.left, origin.top);
ctx.stroke();
ctx.moveTo(origin.left, offset.top);
ctx.lineTo(origin.left, plot.height() + offset.top);
ctx.stroke();
}
And this works, with 2 small snags. The first and most important is that for some reason it makes the very last point of my data series change color! See here:
The point in the upper right-hand corner has turned black. By stepping through the code I can observe that this only happens when the axes are drawn. Before my draw code is called, the point is the correct color. So I think it has something to do with the drawing on the first "stroke". For some reason it seems to then apply the black color to the last point. Any idea on how to fix this?
The second problem is that this code is called only after flot has draw everything else (including the data points) which means that my lines appear on top of points instead of underneath them. This is only a problem for those two points that are very close to the vertical axis. Looking at the flot documentation, it mentions a drawBackground hook, but this doesn't seem to actually exist. I tried using it and it complained the drawBackground was null. So what happened? And is there a better place to hook into and draw my axes? I want to draw after flot has worked out the size of the plot area and before it draws the first series of data points.
What's currently on the website API documentation does not match the newest released version (0.7). In order to use the backgroundDraw hook, you'll need a newer version of flot, directly from their github repository. The newest version is fine, but anything after this commit would be workable.

Rotating text using Textrenderer

Hey, I'd like to display text in a 2D szenario using JOGL. But I can't figure out, how to rotate text using com.sun.opengl.util.j2d.TextRenderer. It does not have any methods concerning the rotation. So I was expecting the modelview matrix to have an effect on the rotation.
val renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36))
[...]
renderer.beginRendering(drawable.getWidth(), drawable.getHeight())
gl.glRotatef(90,0,0,1)
renderer.draw(content, 0, 0)
renderer.endRendering()
Do you know any help?
For me, the following order -- and only the following order -- works:
renderer.beginRendering(...)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glRotatef(...)
renderer.draw(...)
renderer.endRendering()
glPopMatrix()
If I so much as switch the order of the last two lines, it stops working. Don't know why.
Call glRotatef before you beginRendering() the text.
Make sure to glMatrixMode(GL_MODELVIEW) just before calling glRotatef. You don't know what matrix mode the beginRendering method leaves OpenGL in.