Circle appears after pushpull on a trapezoid face - ruby

I'm new to Sketchup scripting. When I extrude face2 below, a circle appears at the base of the face. It only appears after the pushpull and it doesn't appear if I extrude face1. Face1 and face2 are supposed to be the first two walls of a box. Could someone explain this?
ents = Sketchup.active_model.entities
face1 = ents.add_face [1.m, 0, 0], [1.1.m, -0.1.m, 0], [-1.1.m, -0.1.m, 0], [-1.m, 0, 0]
face2 = ents.add_face [-1.m, 0, 0], [-1.1.m, -0.1.m, 0], [-1.1.m, 1.1.m, 0], [-1.m, 1.m, 0]
face1.pushpull(1.m, true)

Your code works for me (I also extruded face2). Could you edit your question and upload a picture of the problem you are describing?

This was a bug in Sketchup, as indicated in comments above.

Related

How to convert a monochrome image to 2d array in ruby

digit 5 monochrome image
How to convert the sample monochrome image to 2d array in ruby.
[[0, 0, 0, 0, 0],
[0, 1, 1, 1, 1],
[0, 1, 1, 1, 1],
[0, 0, 0, 0, 1],
[0, 1, 1, 1, 0],
[1, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[1, 0, 0, 0, 1]]
I had tried do it use pycall plugin. However, I had to import again manual when execute in rails console. Pycall not work sometimes.
require 'pycall'
require 'pycall/import'
include PyCall::Import
pyimport 'numpy', as: :np
pyimport 'PIL.Image', as: :pil_image
image = pil_image.open.(image_path).convert.('1')
img = np.asarray.(image, dtype: np.uint8)
list = img.tolist.().map { |l| l.to_a }
RMagick offers a couple of solutions. Use get_pixels to get an array of Pixel objects. Pixel objects are structures from which you can get the values of the red, green, and blue channel. Because the image is monochrome the channel values will either be 0 or QuantumRange. Scale the values by QuantumRange to force them to either 0 or 1.
Alternatively, use export_pixels. Again, scale the returned values by QuantumRange to get either 0 or 1.
In either case you can minimize the storage requirements (if your image is large) by operating on successive subsets (a single row, for example) of the image.

Find the end of a curved line in a binary image

I'm looking for an algorithm that will detect the end of a curved line. I'm going to convert a binary image into a point cloud as coordinates, and I need to find the end of the line so I can start another algorithm.
I was thinking of taking the average of vectors for the N nearest '1' pixels to each point, and saying that the pixel with the longest vector must be an endpoint, because if a point is in the middle of a line then the average of the vectors will cancel out. However, I figure this must be a problem that is well known in image processing so I thought I'd throw it up here to see if anybody knows a 'proper' algorithm.
If the line will only ever be one or perhaps two pixels thick, you can use the approach suggested by Malcolm McLean in a comment.
Otherwise, one way to do this is to compute, for each red pixel, the red pixel in the same component that is furthest away, as well as how far away that furthest pixel is. (In graph theory terms, the distance between these two pixels is the eccentricity of each pixel.) Pixels near the end of a long line will have the greatest eccentricities, because the shortest path between them and points at the other end of the line is long. (Notice that, whatever the maximum eccentricity turns out to be, there will be at least two pixels having it, since the distance from a to b is the same as the distance from b to a.)
If you have n red pixels, all eccentricities (and corresponding furthest pixels) can be computed in O(n^2) time: for each pixel in turn, start a BFS at that pixel, and take the deepest node you find as its furthest pixel (there may be several; any will do). Each BFS runs in O(n) time, because there are only a constant number of edges (4 or 8, depending on how you model pixel connectivity) incident on any pixel.
For robustness you might consider taking the top 10 or 50 (etc.) pixel pairs and checking that they form 2 well-separated, well-defined clusters. You could then take the average position within each cluster as your 2 endpoints.
If you apply thinning to the line, so your line is just one pixel thick, You can leverage morphologyEX and use MORPH_HITMISS in OpenCV. Essentially you create a template (kernel or filter) for every possible corner (there are 8 possible) and convolve by each one. The result of each convolution will be 1 in the place where the kernel matches and 0 otherwise. So you can do the same manually if you feell that you can do a better job in c.
here is an example. It takes as input_image any image of zeros and ones where the lines are one pixel thick.
import numpy as np
import cv2
import matplotlib.pylab as plt
def find_endoflines(input_image, show=0):
kernel_0 = np.array((
[-1, -1, -1],
[-1, 1, -1],
[-1, 1, -1]), dtype="int")
kernel_1 = np.array((
[-1, -1, -1],
[-1, 1, -1],
[1,-1, -1]), dtype="int")
kernel_2 = np.array((
[-1, -1, -1],
[1, 1, -1],
[-1,-1, -1]), dtype="int")
kernel_3 = np.array((
[1, -1, -1],
[-1, 1, -1],
[-1,-1, -1]), dtype="int")
kernel_4 = np.array((
[-1, 1, -1],
[-1, 1, -1],
[-1,-1, -1]), dtype="int")
kernel_5 = np.array((
[-1, -1, 1],
[-1, 1, -1],
[-1,-1, -1]), dtype="int")
kernel_6 = np.array((
[-1, -1, -1],
[-1, 1, 1],
[-1,-1, -1]), dtype="int")
kernel_7 = np.array((
[-1, -1, -1],
[-1, 1, -1],
[-1,-1, 1]), dtype="int")
kernel = np.array((kernel_0,kernel_1,kernel_2,kernel_3,kernel_4,kernel_5,kernel_6, kernel_7))
output_image = np.zeros(input_image.shape)
for i in np.arange(8):
out = cv2.morphologyEx(input_image, cv2.MORPH_HITMISS, kernel[i,:,:])
output_image = output_image + out
return output_image
if show == 1:
show_image = np.reshape(np.repeat(input_image, 3, axis=1),(input_image.shape[0],input_image.shape[1],3))*255
show_image[:,:,1] = show_image[:,:,1] - output_image *255
show_image[:,:,2] = show_image[:,:,2] - output_image *255
plt.imshow(show_image)

Introduction to algorithms 22.1-7 the contradiction in answer?

I am self-studying Introduction to algorithms, and am confused by the answer to 22.1-7.
Consider a directed graph with no self loop. I think it can be like picture3,
so the incidence matrix B should be
picture4
and the BT should be picture5
so The product of BBT should be picture6
i can understand the value in the diagonal means the the number of edge connect with the point
but in BBT[1][4] the value is 1 (0*1+(-1)*(-1)+(-1)*0)
i confused and don’t understand what wrong with it
To begin with, I think it's excellent that you actually tried to verify it with an example.
Unfortunately, you don't specify your edge numbers, so it's unclear what your incidence matrix refers to.
Suppose we use the following numbering:
Then the incidence matrix is
import numpy as np
b = np.array([[-1, -1, 0], [1, 0, 1], [0, 1, -1]])
>>> b
array([[-1, -1, 0],
[ 1, 0, 1],
[ 0, 1, -1]]
And the product is
>>> np.dot(b, b.T)
array([[ 2, -1, -1],
[-1, 2, -1],
[-1, -1, 2]])
which does not seem to be what you got, but actually makes a lot of sense.

I have a Strange output i do not expect. its similar but.. well odd

So ive taken up Prolog and im trying to learn the ropes of it. Right now im working on a assignment set by the book and ive come quite far. My output nearly matches that which is required but somehow its makes the last few lests that come out come out in a head|tail format in which the tail is a row of dots?
The code ive written looks like this:
%prefix methode. E1 + L = L1
% It takes L, adds E1 in front of it and makes it L1.
prefix(_,[],[]).
prefix(El,[LHead|LTail],[Q|L1]) :- Q = [El|LHead], prefix(El,LTail,L1).
gray(0,[[]]).
gray([],[]).
% this should generate a list of all the gray
% code possibilities with the defined length
gray(N,Lijst) :- N > 0, X is N - 1, gray(X,Prevlist),
reverse(Prevlist, RevPrevlist), prefix(0,Prevlist,Deel1),
prefix(1,RevPrevlist,Deel2), append(Deel1,Deel2,Lijst).
Now the thing it should do is if I give him for example -?gray(3,List).
It should tell me:
List = [[0,0,0],[0,0,1],[0,1,1],[0,1,0],[1,1,0],[1,1,1],[1,0,1],[1,0,0]].
However what it tells me instead is:
List = [[0, 0, 0], [0, 0, 1], [0, 1, 1], [0, 1, 0], [1, 1, 0], [1, 1, 1], [1, 0|...], [1|...]].
As you can see with the output I get my last two lasts have a head|tail construction with a tail consisting of dots. However I do not know what this means or what I did wrong in my code.
Can anybody elaborate why I am getting the dots, and maybe steer me in the right direction to help me solve the problem?
P.S. my apologies if I might've been unclear on certain parts. If I've been so, please say so and I'll try to edit/elaborate.
I just ran this through on swi-prolog:
2 ?- grey(3, List).
Correct to: "gray(3,List)"? yes
List = [[0, 0, 0], [0, 0, 1], [0, 1, 1], [0, 1, 0], [1, 1, 0], [1, 1, 1], [1, 0|...], [1|...]] [write]
List = [[0, 0, 0], [0, 0, 1], [0, 1, 1], [0, 1, 0], [1, 1, 0], [1, 1, 1], [1, 0, 1], [1, 0, 0]]
Notice where it said [write].. I press the 'w' button at that point which forces swi-prolog to dump out the whole list, not just appreviate it with the ...
Not sure if that helps, or if the answer is correct.
If not, suggest explaining the problem/assignment itself in a bit more detail. You've explained your solution in some detail, but it's not clear what the problem is ? To me, anyway.
Edit I see you have edited to clarify.. yep, just looks like prolog was abbreviating the results visually, but was actually holding the correct result. A 'display only' issue.

representing a point inside a cylinder using Mathematica

How to plot a point {x1,y1,z1} inside a cylinder having end points as A = {x,y,z} and B = {x',y',z'} and having radius r, using Mathematica? An example will be appreciated
with a diagram
You can use something similar to
Graphics3D[
{{PointSize[0.03], Point[{0, 0, 0}]},
{Opacity[0.5], Cylinder[{{-1, -1, -1}, {1, 1, 1}}, 0.5]}}
]

Resources