Sketch, how to cut shapes? - sketch-3

I am using Sketch to create a logo. I have 3 shapes (circle and square combined for the fist 2 shapes) that i want to lined up next each other (see image below).
How would i go about cutting the covering shape so that the one below does not show the extra "bits"?
concept
Thanks in advance.

Referring to the circles as B (at the back), M (middle) and F (front)...
Duplicate M, creating duplicate D in exactly the same place.
Select D and F.
Use the 'Intersect' function to create a shape which is the overlap of D and F, with no remaining "bits", leaving you with B > M > D+F

Related

Deriving a matrix values from another 2 matrices

Suppose you have Matrix A.
Suppose also that we have Matrix C
If we have A = B x C and we want to find out the B matrix values which I believe should be 3x3 (Correct me if I am wrong)
Do we need to use matrix inversion here? I did not use algebra since many years.
I do not have a code yet but if someone can provide a snippet that will be great.
This is a problem that I have in image processing where the A , C hold RGB values.
The submitted matrices are just for illustration.
I am trying to solve this problem using Python numpy
I hope that someone can help with it.
Your matrix should be 5x5. As we are dealing with non-square matrices, you could use the generalized inverse of C to obtain B:
import numpy as np
np.random.seed(10)
A = np.random.randint(0,9,(5,3))
C = np.random.randint(0,9,(5,3))
B = np.matmul(A,np.linalg.pinv(C))
print B
Building on percusse's comment, you can do this with numpy.linalg.lstsq. However, this assumes that we are performing matrix left division but the situation is your question is for right division.
Using the fact that you are solving for B with B = A / C, lstsq solves problems of the type A \ C. To convert this into a form for lstsq, we can convert it into the latter problem by:
B = A / C = (C' \ A')'
The ' operator is the transpose. The above is found by linear algebra rules. Specifically, perform two transposes: ((A / C)')' where transposing a matrix twice is simply the result of itself. Also, knowing that (AC)' is equal to C'A' and for a matrix, the inverse of the transpose is equal to the transpose of the inverse you should get the above relationship.
Therefore:
B = numpy.linalg.lstsq(C.T, A.T)[0].T
The output of lstsq is a tuple where the first element is the actual solution.
Take note that for your particular example, C is a rank-deficient matrix so you won't be able to reconstruct A properly from B and C.

Is there a way to describe attributes, using just graphs, links and nodes?

I've been thinking about this for a while but I can't seem to get my head around this.
(1) Say you have a simple graph with links and nodes. Some nodes are green and some nodes are red.
(2) It seems to me that we could represent this by adding two special 'color' nodes, and linking them to the nodes that have that color.
(3) However, 'being a color node', is in itself an attribute. So we could represent this, again, by adding a special node that represents this, and linking the color nodes to that one. This could go on ad infinitum.
see this image for illustration
Is there a way to do describe attributes, using only nodes and links? I.e. is there a way to break out of the infinite regression without using 'special' nodes?
In various data structures (linked lists, trees, graphs etc.) nodes always contain some data.
This is also necessary in recursive data structures like a linked list or a tree, were the nodes of such data structures include themselves in data. This is because a list can be a list of a list and a tree can be a tree of a tree of a tree etc.
In a graph you could kind of get a pass for nodes, because for instance you can define and represent a graph with a matrix with number nodes. However, if you want it to be for colours, you would need a dictionary (or an associative arrays) to map your values with other values.
This graph can be represented by a matrix like this:
5|Y x x x Y Dictionary // a, b, c, d, e could be colours or other atomic values mapped.
4|x x Y Y x a -> 1
3|Y x Y Y Y b -> 2
2|Y Y x x x c -> 3
1|Y Y Y x Y d -> 4
- - - - - e -> 5
1 2 3 4 5
x -> represents there's no link (edge) between the nodes.
Y -> represents there's a link (edge) between the nodes.

Find the position of a circle tangent to two other circles

Say there are 3 circles, A, centered at point a, B centered at point b, and C, centered at point c. Each has a known radius independent of the others, Ar, Br, and Cr. The positions of a and b are known, but the position of c isn't.
The distance between a and b will always be between (Ar + Br) and (Ar + Br + (2 * Cr)).
I'm looking for a pseudo-code algorithm to find the position of c so that circles A and C are tangent, and circles B and C are tangent. There ought to be two solutions unless a and b are at their maximum allowed distance, in which case there would only be one.
Thank you, any help is much appreciated.
"Inflate" the circles A and B by Rc at the same time as you shrink C to a single point. Then the center of C appears as the intersection of the two inflated circles.
Write the implicit equation of the two circles and subtract one from the other; the quadratic terms cancel out, leaving the equation of a straight line (the line through the two intersection points).
(X-Xa)² + (Y-Ya)² = (Ra+Rc)²
(X-Xb)² + (Y-Yb)² = (Rb+Rc)²
=> by subtraction
(Xa-Xb)(2X-Xa-Xb) + (Ya-Yb)(2Y-Ya-Yb) = (Ra-Rb)(Ra+Rb+2Rc)
To solve this, you can express Y as a function of X using the linear relation, then substitute Y in the equation of one of the circles and solve the second degree equation in X, yielding two solutions.

About affine transform (translation )

For affine 4*4 transformation, I saw two representation in different text
one is
L T
0 1
Another is
L 0
T 1
L is the linear part, T is the translation part; I am wondering which is correct?
Both forms are correct. The first is used in left-multiply matrix by column vector
ResultVector = Matrix*V (for example, in OpenGL), and the second - in right-multiply convention with row vector V*Matrix (for example, in DirectX)

How can I find the 3D coordinates of a projected rectangle?

I have the following problem which is mainly algorithmic.
Let ABCD be a rectangle with known dimensions d1, d2 lying somewhere in space.
The rectangle ABCD is projected on a plane P (forming in the general case a trapezium KLMN). I know the projection matrix H.
I can also find the 2D coordinates of the trapezium edge points K,L,M,N.
The Question is the following :
Given the Projection Matrix H, The coordinates of the edges on the trapezium and the knowledge that our object is a rectangle with specified geometry (dimensions d1, d2), could we calculate the 3D coordinates of the points A, B, C, D ?
I am grabbing images of simple rectangles with a single camera and i want to reconstruct the rectangles on space. I could grab more than one image and use triangulation but this is not desired.
The projection Matrix alone isn't enough since a ray is projected to the same point. The fact that the object has known dimensions, makes me believe that the problem is solvable and there are finite solutions.
If I figure out how this reconstruction can be made I know how to program it. So I am asking for an algorithmic/math answer.
Any ideas are welcome
Thanks
You need to calculate the inverse of your projection matrix. (your matrix cannot be singular)
I'm going to give a fairly brief answer here, but I think you'll get my general drift. I'm assuming you have a 3x4 projection matrix (P), so you should be able to get the camera centre by finding the right null vector of P: call it C.
Once you have C, you'll be able to compute rays with the same direction as vectors CK,CL,CM and CN (i.e. the cross product of C and K,L,M or N, e.g. CxK)
Now all you have to do is compute 3 points (u1,u2,u3) which satisfies the following 6 constraints (arbitrarily assuming KL and KN are adjacent and ||KL|| >= ||KN|| if d1 >= d2):
u1 lies on CK, i.e. u1.CK = 0
u2 lies on CL
u3 lies on CN
||u1-u2|| = d1
||u1-u3|| = d2
(u1xu2).(u1xu3) = 0 (orthogonality)
where, A.B = dot product of vectors A and B
||A|| = euclidean norm of A
AxB = cross product of A and B
I think this problem will generate a set of possible solutions, at least in 2D it does. For the 2D case:
|
-----------+-----------
/|\
/ | \
/ | \
/---+---\VP
/ | \
/ | \
/ | \
/ | \
/ | -- \
/ | | \
/ | | \
In the above diagram, the vertical segment and the horizontal segment would project to the same line on the view plane (VP). If you drew this out to scale you'd see that there are two rays from the eye passing through each end point of the unprojected line. This line can be in many positions and rotations - imagine dropping a stick into a cone, it can get stuck in any number of positions.
So, in 2D space there are an infinite number of solutions within a well defined set.
Does this apply to 3D?
The algorithm would be along the lines of:
Invert the projection matrix
Calculate the four rays that pass through the vertices of the rectangle, effectively creating a skewed pyramid
Try and fit your rectangle into the pyramid. This is the tricky bit and I'm trying to mentally visualise rectangles in pyramids to see if they can fit in more than one way.
EDIT: If you knew the distance to the object it would become trivial.
EDIT V2:
OK, let Rn be the four rays in world space, i.e. transformed via the inverse matrix, expressed in terms of m.Rn, where |Rn| is one. The four points of the rectange are therefore:
P1 = aR1
P2 = bR2
P3 = cR3
P4 = dR4
where P1..P4 are the points around the circumference of the rectangle. From this, using a bit of vector maths, we can derive four equations:
|aR1 - bR2| = d1
|cR3 - dR4| = d1
|aR1 - cR3| = d2
|bR2 - dR4| = d2
where d1 and d2 are the lengths of the sides of the rectangle and a, b, c and d are the unknowns.
Now, there may be no solution to the above in which case you'd need to swap d1 with d2. You can expand each line to:
(a.R1x - b.R2x)2 + (a.R1y - b.R2y)2 + (a.R1z - b.R2z)2 = d12
where R1? and R2? are the x/y/z components of rays 1 and 2. Note that you're solving for a and b in the above, not x,y,z.
m_oLogin is right. If I understand your goal, the image the camera snaps is the plane P, right? If so, you're measuring K,L,M,N off the 2D image. You need the inverse of the projection matrix to reconstruct A,B,C, and D.
Now I've never done this before, but it ocurrs to me that you might run into the same problem GPS does with only 3 satellite fixes - there are two possible solutions, one 'behind' P and one 'in front' of it, right?
The projection matrix encapsulates both the perspective and scale, so the inverse will give you the solution you are after. I think you are assuming that it only encapsulates the perspective, and you need something else to choose the correct scale.

Resources