How to get complete solution for Rubik's Cube from kociemba Library - solver

I tried kociemba library in python,
And here is my code
import kociemba
cube = "rorrybobogwyrrgwyobryybggoowygwwbrgbyywoogbrrbbgwgwyow"
print(cube)
cube = cube.replace('y', 'U')
cube = cube.replace('r', 'R')
cube = cube.replace('b', 'F')
cube = cube.replace('w', 'D')
cube = cube.replace('o', 'L')
cube = cube.replace('g', 'B')
print(cube)
solution = kociemba.solve(str(cube))
print(solution)
And the output is U D' L2 U' F' R' F L B L2 B D F2 U F2 D2 B2 D B2 R2 U,
But applying this sequence of steps in my rubik's cube doesn't completely solve it, Can somebody please suggest any corrections to completely solve my cube from any scrambled state, I really don't need to solve under 20 steps and all, it can be even 50 steps, but I need complete solution for the cube

Related

Find point perpendicular to 2 points

It seems I am bad at vectors and math or forgot my entire university studies...
I have A, B, C points coordinates (X, Y, Z) where Z = 0.
C is placed in a half distance between A, B points.
D, E points are in parallel to A,B line
Any idea how to find D and E positions with three.js?
A, B, C are Vector3 three.js objects.
Any help is appreciated.
If C is at half the distance between A and B, offset orthogonally, as your figure seems to indicate, then it is simple:
D = C - 0.5AB and
E = C + 0.5AB,
where AB is the vector from A to B.
In THREE.js, you could write it for example like this:
const abHalf = b.clone().sub(a).multiplyScalar(0.5);
const d = c.clone().sub(abHalf);
const e = c.clone().add(abHalf);
though as usual when working with vectors, there are many other ways to calculate it; you may pick your favourite approach.
Is this what you meant?

Calculate if a bullet hits the balloon

I have this problem I can't figure out and need help.
The problem is about calculating how many balloons are hit by a pellet gun. Balloons positions are described by 3D coordinates (X,Y,Z) and radius R. The gunshot is defined by 3D location of the end of the barrel "p" (Px,Py,Pz) and vector "v" (Vx, Vy, Vz) describing the direction barrel is pointing to.
I've tried to implement the solution suggested here: https://math.stackexchange.com/questions/1939423/calculate-if-vector-intersects-sphere
// C = center of sphere
// r = radius of sphere
// P = point on line
// U = unit vector in direction of line
Q = P - C;
a = U*U; // should be = 1
b = 2*U*Q
c = Q*Q - r*r;
d = b*b - 4*a*c; // discriminant of quadratic
if d < 0 then solutions are complex, so no intersections
if d >= 0 then solutions are real, so there are intersections
But the problem with this is that I get intersection with balloons that are positioned behind the gun. How can I modify this algorithm in order to produce the correct result? Or is my approach maybe wrong?
You need to actually solve the quadratic equation defined by your variables a, b and c.
Often, there are math libraries to do this, something like:
(t1,t2) = QuadraticSolve(a, b, c);
You can also do it manually for each parameter:
t1 = (-b + sqrt(b*b - 4*a*c)) / (2*a)
t2 = (-b - sqrt(b*b - 4*a*c)) / (2*a)
If t1 or t2 is positive then that intersection is in front of your gun.

Transform points from one triangle to another triangle. 3D version

Here is this question 2D version.
because I use unity3D,I have to transform points from one triangle to another triangle in 3D.
I have two triangles with the corresponding coordinates. Now I have to transfer further points from the first triangle to the second triangle. I've tried to solve it with emgu, but I have not found a way. It is important for me that the points are transferred linearly. Does anyone have an idea how I can solve this with C #?
Transformation between two triangles
2D version answer by John Alexiou
The approach is independent of the language: If you have a matrix U (and V) where each column contains the coordinates of one source points (and target points respectively). Then let X be the linear transformation that transforms the source points to the target points. This is the matrix we would like to recover. Then we have
V = U*X
where * is the matrix multiplication. This means we can simply compute
X = inv(U) * V
If U is not invertible, this means the three source points are not linearly independent, in that case you can still hope to recover a transformation X by using a pseudoinverse instead. But you should definitely check if V - U*X is as close to zero as possible. If this residual is large, you know that the transformation does not work out.
You don't specify how the points of the first triangle are given. If we assume that they are known by local coordinates (u, v), then in the source triangle,
P = A + u AB + v AC
and in the destination
P'= A' + u A'B' + v A'C'
And if the points are given by their 3D coordinates (x, y, z), you have to solve the 3x2 system
P = A + u AB + v AC
for u and v and plug in the destination triangle. Using vector calculus,
AP x AB = u AB x AB + v AC x AB = v AC x AB
AP x AC = u AB x AC + v AC x AC = u AB x AC
and
(AP x AB).(AC x AB) = v (AC x AB)²
(AP x AC).(AB x AC) = u (AB x AC)²

Find the center of a circle (x and y position) with only 2 random points and bulge

im trying to find the center of a circle. the only information I have is:
Two random points in the circle and the circle bulge. So far i've manage to calculate the radius of the circle (at least i think i did). Ill post bellow the equasions ive used so far.
these are just random values and will change on user input)
PointA(x = 10, y = 15)
PointB(x = 6, y = 12)
circle_bulge = 0.41
distance = PointB - PointA
radius = (distance / 4) * (circle_bulge + (1 / circle_bulge ))
if this math is incorrect, please let me know, but keep in mind that i need to find the X and Y coordinates of the center of the circle
Here is a picture of the problem:
By definition the bulge is b = tg(Alpha/4)
From the trigonometric formula: tg(2 angle) = 2tg(angle)/(1-tg2(angle))
applied to angle = Alpha/4 and using the definition of bulge:
tg(Alpha/2) = 2 b/(1-b2)
On the other hand
tg(Alpha/2) = s/d
Then
s/d = 2 b/(1-b2) and
d = s(1-b2)/(2 b)
which allows us to calculate d because b is known and s = ||B - A||/2, where ||B - A|| denotes the norm of the vector B - A.
Now, let's calculate
(u,v) = (B - A)/||B - A||
Then ||(u,v)|| = 1, (v,-u) is orthogonal to B - A, and we have
C = (v,-u)d + (A+B)/2
UPDATE
Pseudo code to compute the center
Inputs:
A = (a1, a2), B = (b1, b2) "two points"; b "bulge"
Calculations:
"lengths"
norm := sqrt(square(b1-a1) + square(b2-a2)).
s := norm/2.
d := s * (1-square(b))/(2*b)
"direction"
u := (b1-a1)/ norm.
v := (b2-a2)/ norm.
"center"
c1 := -v*d + (a1+b1)/2.
c2 := u*d + (a2+b2)/2.
Return C := (c1, c2)
Note: There are two solutions for the Center, the other one being
c1 := v*d + (a1+b1)/2.
c2 := -u*d + (a2+b2)/2.
Return C := (c1, c2)
I believe that you have all the required math in this reference: http://autocad.wikia.com/wiki/Arc_relationships
The center of the circunference has to be in the straight line that passes trough the middle point of the segment with perpendicular vector AB. You know the angle of the triangle formed by the three points because you know the bulge so you have to solve a simple equation. Try it out, if you can not I will try to help you.
Ignacio is right pointing out that there will be two solutions.
EDIT
The middle point is given by:
M = (A + B) / 2
The AB vector is gien by:
AB = A-B
The center of the circle C with coordinates (X, Y) has to be in the line given by:
((X, Y) - M) * AB = 0 //where * is the scalar vector product
The isosceles triangle generated by the points A, B and C has an angle opposite of the AB segment:
Angle = 4 arctan(bulge)
now we can compute the distance from the center C to A that we call d1 and half the distance between A and B that we call d2 we know then that
sin (Angle/2) = d2/d1
This will give you the second equation for X and Y that is quadratic (it has two solutions).
Excuse the notation but I do not know how to insert math here :-)

computational geometry - projecting a 2D point onto a plane to determine its 3D location

The following is what I am trying to figure out.
Question - Explain how you can project a 2D point onto a plane to create a 3D point.
I want to know how I would go about figuring this out. I have looked through a computational geometry book and looked for anything that may relate to what I'm trying to figure out. There was no information given along with the question about the computational geometry problem. The thing is I don't know anything about computational geometry< so figuring this out is beyond my knowledge.
Can anyone point me in the right direction?
If I understood this correctly you want to project points on the 2D plane onto a plane with a different orientation. I’m also going to assume that you are looking for the orthogonal projection (i.e. all points from the xy-plane are to be projected onto the closest point on the target plane).
So we have the equations of the two planes and the point we want to project:
The original 2D plane: z = 0, with the normal vector n1 = (0, 0, 1)
The target plane: ax + by + cz + d = 0 with the normal vector n2 = (a, b, c)
Point P: (e, f, 0) which obviously lies in the xy-plane
Now, we want to travel from point P in the direction of the normal of the target plane (because this will give us the closest point on the target plane). Hence we form an equation for the line which starts at point P, and which is parallel to the normal vector of the target plane.
Line L: (x,y,z) = (e,f,0) + t(a,b,c) = (e+ta, f+tb, tc) , where t is a real valued parameter
Next, we want to find a point on the line L which also lies on the target plane. Hence, we plug the line equation into the equation for the target plane and receive:
a(e+ta) + b(f+tb) + c * tc + d= 0
ae + bf + d + t(a2 + b2 + c 2) = 0
t = - (ae + bf + d) / (a2 + b2 + c 2)
hence the projected point will be:
Pprojected = (e + ka, f + kb, kc), where k = - (ae + bf + d) / (a2 + b2 + c 2)
With all the variables in the solution about, it might be a bit hard to grasp if you are new to the area. But really, it is rather simple. The things you have to learn are:
The standard equation for a plane: ax + by + cz + d = 0
How to extract the normal vector from the equation of the plane
What the normal vector is (a vector which is perpendicular to all position vectors in the plane)
The parametric representation of a line: (x, y, z) = u + t*v* , where u is a point which lies on the line, t is a real valued parameter and v is a vector parallel to the line.
The understanding that the closest path between a point and a plane will be parallel to the normal of the plane
If you grasped the above concepts, computing the projection is simple:
Compute the normal vector of the target plane. Starting from the point that you want to project, travel parallel to the computed normal vector until you reach the plane.

Resources