Hello,
I write programs for large CNC routers, and I'm trying to make a parametric program that uses an ellipse in it. I need to know the formula or formulas used to produce the arcs that make up a pellipse so that I can get the radii, and end points of each arc. Any help would be greatly appreciated, Thanks.
-Norm
Solved! Go to Solution.
Solved by corey.downum. Go to Solution.
And you really want to create a program in vba, WITHOUT? autocad or other cad editors, which creates arcs (or polylines?) in form of a ellipse?
I am Just interested in why you ask for, after all helpful links and explanations.
Well basically my compnay uses autocad to create the ellipse but every time the size changes, i have to process the new one and make a new program in another software package using the points from autocad.
My ultimate goal is ultimately to find out how i can programmically figure out each X,Y coordinate and a radius or centre point for the arcs so i can make a parametric program in the other sotware, saving alot of time and effort.
I found an excel formuala here
https://www.excelforum.com/excel-charting-and-pivots/528378-graphing-ellipse-equation.html
However because we use PELLISE in Autocad, the formula does not seem to match what i need as PELLIPSES are created using the method supplied earlier, i just can't figure out how to make sense of that using formulas in excel or vba
I think it is doable. Without the groundwork provided by AutoCAD, though, the developer needs to create the math structure themselves.
It's interesting. I'll try to give it some thought this weekend.
It is indeed!
The green ones are the lines of code where the formula provided in the link below works, (P1, P3 and P5 in the bottom image) It's P2 and P4 that is stumping me
The attached Excel spreadsheet will calculate P2 and P4. The sample data I used was from the file EllipseApprox.
After calculating the coordinates for triangle P1, P3, P7 the task is to find P2 at the intersection of the angle bisectors at p1 and p7. Vector C is the angle bisector at p1, D the bisector at p7.
The general equation for the angle bisector can be expressed as:
C = |B| A + |A| B (bold font indicates a vector)
Using the parametric definition of a straight line: P = PA + t (PB-PA) for the angle bisector lines from P1 and P7 I calculated P2. In a similar fashion P4 is calculated.
Just enter the coordinates of the rectangle in the yellow boxes and the pellipse points P2, P3, and P4 are calculates. I could add the calculation for C1, C2, C3, and C4 if you wish which, as you know are at the bisectors of the chords P5, P4, P3, P2, P1.
Also, I could post my reviation when I have more time if you wish.
Lee
Very nice. This situation is well in hand.
Charts, Lee? Now you're just showing off.
What you did there was nothing short of amazing.
You've made me feel like I know absolutely nothing ha
That is a massive help, thankyou so much Lee, if I could ask one more favour and get your assitance with calculating the C1 + C2 + C3 + C4 points so i could get the radii, my program will be complete!
Again, thankyou, you saved me days of heartache trying to figure this out myself!
@Ry91, this has been a fun project. Thank you for the compliment.
The attached Excel file adds the location of the arc centers, c1, c2, c3, c4, and their radii. Just enter your data into the yellow cells and the output is in the green cells.
The calculation required the determination of two points on the perpendicular bisector between two points. Since this calculation was required several time I created a custom Excel function to compute the two points. The Excel file is therefore a Macro enable file (.xlsm).
perpbi(A,B) is an array function. It requires the x,y coordinates of two points (A and B) and outputs four values, the x,y coordinates of the mid-point and another point on the perpendicular bisector. Most Excel users are not familiar with array functions. To enter an array function you select a range of cells, enter the expression and then instead of hitting Enter, you hit Ctrl-Shift-Enter when you are done typing the expression. The braces {} indicate it is an array function. Do not type the {}, they are added when you hit CTrl-Shift-Enter. For example, the cells b35:c36 contain: {=perpbi(B4:C4,B23:C23)}. It takes the x and y coordinates found in B4:C4, and B23,C23 and calculates the x,y values for 2 points.
I created a second custom VBA function inters(A,B,C,D) to determine the intersection of two lines defined by two sets of two points.
Here's a listing of the two functions.
Function inters(A, B, C, D) ' 10/30/2018 L. Minardi ' an array function 'input = 4 points defining two lines. Each point is defined by two adjacent cells containing the ' the x and y coordinates of the point. ' Ax Ay ' Bx By ' Cx Cy ' Dx Dy 'output = a 2 element array containing the x,y coordinates of the ' point of intersection ' X Y x y coordinates of the intersection of line AB with line CD Dim point(1 To 2) As Variant ax = A(1) ay = A(2) bx = B(1) by = B(2) cx = C(1) cy = C(2) dx = D(1) dy = D(2) Top = (bx - ax) * (cy - ay) - (cx - ax) * (by - ay) bot = (dx - cx) * (by - ay) - (dy - cy) * (bx - ax) If bot <> 0 Then u = Top / bot point(1) = cx + u * (dx - cx) point(2) = cy + u * (dy - cy) Else point(1) = "parallel" point(2) = "lines" End If inters = point End Function Function perpbi(A, B) ' 10/30/2018 L. Minardi 'input = 2 points defining a line. Each point is defined by two adjacent cells containing the ' the x and y coordinates of the point. ' Ax Ay ' Bx By ' Output = a 2 row x 2 column array that contains the xy coordinates of: ' Cx Cy - a point at the midpoint between A and B ' Dx Dy - a point on the perpendicular bisector (but not C) Dim points(1 To 2, 1 To 2) As Variant ax = A(1) ay = A(2) bx = B(1) by = B(2) points(1, 1) = (ax + bx) / 2 points(1, 2) = (ay + by) / 2 points(2, 1) = points(1, 1) + ay - by points(2, 2) = points(1, 2) - (ax - bx) perpbi = points End Function
Thanks Lee, absolutely astounding.
Can't see an attached file though!
How does one even have the capacity to know all this stuff!
Attached is a zipped version of the file. Sorry about that. I didn't notice that the Forum didn't accept the xlsm files.
I used vector math to calculate the points. It is a really neat natural way to solve geometry problems, much better than using trig. I think people who think graphically including most CAD users would learn it quickly with the right teacher/book/tutorials. I also like Excel/VBA although many programmers do not. I like that it works well with Excel for most of the things I want to do. VLISP does allow you to work more easily with vectors but the syntax is awful.