Need some help with the math
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- sliptonic
- Veteran
- Posts: 3460
- Joined: Tue Oct 25, 2011 10:46 pm
- Location: Columbia, Missouri
- Contact:
Need some help with the math
The attached file has a sketch with a single degree of freedom which is the angle of the long blue line. The angle is currently a reference angle but if you turn it into a regular constraint, the sketch becomes locked. With it set as a reference angle, the smaller circle can roll around the larger one.
I need a function that, given this arrangement, returns the coordinates of the center of the smaller circle for a given input angle. The sketch is just to demonstrate the setup.
I posted the problem on stackexchange and got some answers but I still don't understand how to solve the system of equations in python.
I need a function that, given this arrangement, returns the coordinates of the center of the smaller circle for a given input angle. The sketch is just to demonstrate the setup.
I posted the problem on stackexchange and got some answers but I still don't understand how to solve the system of equations in python.
- Attachments
-
- bendingexperiment.FCStd
- (8.46 KiB) Downloaded 37 times
- mpetrasinovic
- Posts: 106
- Joined: Sat Feb 22, 2020 10:19 am
- Location: Belgrade, Serbia
- Contact:
Re: Need some help with the math
From the following image, you can see that there are two possible solutions. You need to decide which one is right using additional condition.
In python, you can use the following code.
In python, you can use the following code.
Code: Select all
R1 = 20
R2 = 11
alpha = 50
alpha_r = alpha*math.pi/180
k = math.tan(math.pi/2+alpha_r)
n = R1*math.sin(alpha_r)-k*R1*math.cos(alpha_r)
a = 1+k**2
b = 2*k*(n+R2)
c = (n+R2)**2-(R1+R2)**2
x1 = (-b+math.sqrt(b**2-4*a*c))/(2*a)
y1 = k*x1+n+R2
x2 = (-b-math.sqrt(b**2-4*a*c))/(2*a)
y2 = k*x2+n+R2
Last edited by mpetrasinovic on Mon Apr 27, 2020 8:55 pm, edited 1 time in total.
Re: Need some help with the math
'alpha' should be used to compute 'alpha_r'.
- mpetrasinovic
- Posts: 106
- Joined: Sat Feb 22, 2020 10:19 am
- Location: Belgrade, Serbia
- Contact:
Re: Need some help with the math
- mpetrasinovic
- Posts: 106
- Joined: Sat Feb 22, 2020 10:19 am
- Location: Belgrade, Serbia
- Contact:
- sliptonic
- Veteran
- Posts: 3460
- Joined: Tue Oct 25, 2011 10:46 pm
- Location: Columbia, Missouri
- Contact:
Re: Need some help with the math
Sure!
And if you guys want to help with more math, there's one more area described below that I haven't finished.
Short version.
I started playing with wire bending. I thought that adding a wire-bending capability to the Path workbench would be a nice feature.
Much Longer Version
(Background Thread and some videos)
Wire bending is pretty different from regular CNC milling but there's enough overlap to be interesting. I'm not sure exactly what this would look like in Path but I have some ideas.
Lenny
For my own experimentation, fun, and to make some content for my youtube channel, I decided to turn Lenny The Big Dumb Bot into the world's dumbest wire bender. Now this is absolutely the WRONG way to build a wire bender. If I actually needed a wire bender I wouldn't want this one. In fact, no one in their right mind would do it this way but Lenny is what I have so that's what I'm going to do.
Instead of a moving mechanism that grabs the wire and bends it around the tip, Lenny is going to move the tip around a fixed bending mandrel (green). The math problem in this thread is needed to calculate the ending position of the tip for a given wire bend angle.
What's Needed:
Besides building the bending head and getting Lenny to do his thing, I still need to start with a wire in FreeCAD and calculate the bends and rotations. The process will take a wire as input. It will extract the vertices of sharp bends and discretize arcs into a segments of desired length. That's easy and I've done it already.
The next thing is to take those vertices and turn it into "B-code". B-code is industry standard for wire benders. It's just a table of three values. Length, Rotation, and bend Angle. You start at one end of the wire:
Length is the distance from one vertex to the next and the amount of wire Lenny will Feed out.
Rotation is the angle to rotate to bring the next vertex into the bending plane.
Angle is how much to bend.
Repeat for each vertex in the list.
I found a decent paper that describes it very well. The math is included but no python code. So if someone wants to help, this would be a great place to jump in.
Once I have B-code, a custom postprocessor will turn it into G-code that Lenny can use.
- mpetrasinovic
- Posts: 106
- Joined: Sat Feb 22, 2020 10:19 am
- Location: Belgrade, Serbia
- Contact:
Re: Need some help with the math
In python, you can use the following code to obtain the same results as in the paper.sliptonic wrote: ↑Tue Apr 28, 2020 4:26 pm I found a decent paper that describes it very well. The math is included but no python code. So if someone wants to help, this would be a great place to jump in.
Code: Select all
import numpy as np
P = np.array([[39.92, -54.48, 7.7],
[24.8, 3.586, 7.69],
[-4.71, 9.002, 0],
[-4.35, -18.32, -12.39],
[-5.32, 20.99, -19.75],
[ -8.53, 39.59, -92.33],
[ -13.22, 25.77, -165.9],
[-14.9, -12.96, -175.75],
[-15.01, 15.11, -186.33],
[14.5, 9.43, -186.36],
[29.05, -48.76, -187.38]])
L = np.linalg.norm(P[:-1,:]-P[1:,:] ,axis=1)
p = np.cross(P[2:-1,:]-P[:-3,:],P[1:-2,:]-P[:-3,:])
q = np.cross(P[3:,:]-P[1:-2,:],P[2:-1,:]-P[1:-2,:])
beta = np.insert(np.degrees(np.arccos(np.sum(np.divide(p,np.linalg.norm(p,axis=1)[:,None])*np.divide(q,np.linalg.norm(q,axis=1)[:,None]),axis=1))),0,0)
v1 = P[:-2,:]-P[1:-1,:]
v2 = P[2:,:]-P[1:-1,:]
alpha = np.degrees(np.arccos(np.sum(np.divide(v1,np.linalg.norm(v1,axis=1)[:,None])*np.divide(v2,np.linalg.norm(v2,axis=1)[:,None]),axis=1)))
theta = 180-alpha
- sliptonic
- Veteran
- Posts: 3460
- Joined: Tue Oct 25, 2011 10:46 pm
- Location: Columbia, Missouri
- Contact:
Re: Need some help with the math
That's fantastic! Thank you again.
I'll report back when I've got the big dummy bending wires
I'll report back when I've got the big dummy bending wires