Jump to content

Curve Generator


---
 Share

Recommended Posts

I recently helped someone on Facebook develop a curve on a cylinder using Excel. He did not have a model. The unique thing was he needed to move in the Z so it was a 2d helical curve.

Then, I created a program in Python that creates a text file that can be read into a curve feature. It was my very first project using python.

Below is a a link to the .exe on my google drive. Please feel free to try and share.

https://drive.google.com/file/d/1zWUy0B ... sp=sharing

Create Curve Points.pdf319508578_181188614589276_6673600375303947328_n.jpg

Link to comment
Share on other sites

Let's say, programming languages are divided mainly as C type and Pascal type.

Python is more likely like LUA or PHP - need interpreter for compile.
C, C++ and C# are so similar and yet so different languages.
Google says:

Please sign in to view this quote.

Link to comment
Share on other sites

I've created a folder which may allow you to download. Previously will probably not work as I have the files into a folder.

https://drive.google.com/drive/folders/ ... sp=sharing

On my original post, I added a sketch of what user was trying to accomplish. And a pdf of the excel process

I considered showing the user how to create a CAD cylinder feature in Calypso, but trying to explain how to get a section cut at an angle thru his required points was going to be a bit of a challenge. Not impossible but thought excel would be the easier way for his application.

Using the point generator in Calypso, does anyone know how to handle the changes in Z to create the same helical curve?

calypso point generator.JPG

Link to comment
Share on other sites

Please sign in to view this quote.

Be gentle. This is my first project and the goal was to make it work. I'm guessing I may have some room to "trim the fat".
---------------------------------------------------------------------------------------------
import math

file_name = input('Enter desired file name: ')
curve_radius = float(input('Enter curve radius: '))
angle_start = math.radians(float(input('Enter starting angle: ')))
angle_start_deg = math.degrees(angle_start)
angle_end = math.radians(float(input('Enter ending angle: ')))
angle_end_deg = math.degrees(angle_end)
angle_increment = math.radians(float(input('Enter angle increment: ')))
angle_increment_deg = math.degrees(angle_increment)
angle_range = math.degrees(float(angle_end - angle_start))
number_points = int((math.radians(angle_range / angle_increment)+1))
z_start = float(input('Enter starting Z value: '))
z_end = float(input('Enter ending Z value: '))
z_delta = z_end - z_start
z_increment = z_delta / (number_points - 1)

print('-' * 50)
print(f'Curve Radius = {curve_radius:.4f}')
print(f'Start Angle = {angle_start_deg:.4f}')
print(f'End Angle = {angle_end_deg:.4f}')
print(f'Angle Range = {angle_range:.4f}')
print(f'Angle Increment = {angle_increment_deg:.4f}')
print(f'Number of Points = {number_points}')
print(f'Z Start = {z_start:.4f}')
print(f'Z End = {z_end:.4f}')
print(f'Z Range = {z_delta:.4f}')
print(f'Z Increment = {z_increment:.8f}')


heading = ['XNOM', 'YNOM', 'ZNOM', 'UNOM', 'VNOM', 'WNOM']
print('\t'.join(map(str,heading)))
with open(file_name + '.txt', 'w') as f:
f.write("\t".join(heading))
f.write('\n')

angle_current = angle_start
z_current = z_start

for i in range(0, int(number_points)):
xnom = math.cos(angle_current) * curve_radius
ynom = math.sin(angle_current) * curve_radius
znom = z_current
unom = math.cos(angle_current)
vnom = math.sin(angle_current)
wnom = float(0)

print(f"{xnom:.8f}\t{ynom:.8f}\t{znom:.8f}\t{unom:.8f}\t{vnom:.8f}\t{wnom:.8f}")

angle_current = angle_current + angle_increment
z_current = z_current + z_increment

with open(file_name + '.txt', 'a') as f:
f.write(f'{xnom:.8f}\t{ynom:.8f}\t{znom:.8f}\t{unom:.8f}\t{vnom:.8f}\t{wnom:.8f}\n')

input()
Link to comment
Share on other sites

Please sign in to view this quote.

Thanks Jeff.

Back in 81-84, I majored in computer science but couldn't keep up going to school at night while working fulltime as a cnc programmer/machinist. I loved programming but didn't want to start over in a new career as an entry-level programmer. Always had a desire to get back into it. I've been dabbling with python here and there during this past year but never had a reason to build a program until now...lol PCM has been calling me to do something but just waiting for the right something.
Link to comment
Share on other sites

The point generator can generate a curve with a mathematical formula.
Some examples: CALYPSO curve with Point generator
Formel mit OK schließen / Close the formula with OK

1.) einen Spirale als Kurve definieren / define a spiral as a curve
--------------------------------
Start index 1
End index 3600
Increment 1

point((cos(index) *(0.5 * index)) , (sin(index)*(0.5* index)) ,0 ,0,0,1)


2.) einen Spirale in Z (wie ein Gewindebohrer) als Kurve definieren / define a spiral in Z (like a tap) as a curve
----------------------------------------------------------------
Start index 1
End index 1440
Increment 10

point(sin(index),cos(index),(index *(1/360)),0,0,1)
//oder
point(sin(index),cos(index),(index *(1/360)),sin(index),cos(index),0)


3.) einen Kreis als Kurve definieren / define a circle as a curve
--------------------------------
Start index 1
End index 360
Increment 1

point(sin(index),cos(index),0,0,0,1)


4.) eine Parabel als Kurve definieren / define a parabola as a curve
----------------------------------
Start index -10
End index 10
Increment 0.1

point(index,squared(index),0,0,0,1)

882_bef19eeac73ffe4c9acd1f8d48edf156.png
Link to comment
Share on other sites

Please sign in to view this quote.

So it's like BASIC 🤠
Or not.
I started to look into Python when we got our GOM scanner, but coming from BASIC, the way Python handles subscripts in string slicing and counters in FOR loops drove me nuts. This is so error-prone when for decades you've been used to the convention that counting from 1-10 literally meant starting at 1 and ending at 10. In Python it means ending at 9. 😮
Well, but that's not why I rarely use it. I just don't find the time.
Link to comment
Share on other sites

Please sign in to view this quote.

Nowadays are all loops starting from 0 ( if we speak about FOR x IN y - loops )
Defining classical ( int a = 1; a <=10; a++ ) will give you 1-10 loop ( perhaps this code is not suitable for python - didn't use this lang )
Link to comment
Share on other sites

Please sign in to view this quote.

Thank you Guenter. That was too easy....lol

,(index *(1/360)) is what I was looking for. I was too focused on producing correct z value. I wasn't thinking I could move the curve in Z once curve was created. I think I can still put a start Z in this formula. ,xxx + index *(1/360) where xxx = Z starting height, correct?
Link to comment
Share on other sites

* * * UPDATE * * *

I don't think (index * (1/360)) will work if I need to control the range in Z, i.e. Let's say I want to start at Z0 and end at Z25. The Z formula needs to take the difference in Z divided by the number of steps. Are there a variable names for Start Index, End Index or Step so I could calculate the number of steps in order to calculate the Z step?

Screenshot 2022-12-16 092420.jpg

Link to comment
Share on other sites

I am not sure what you mean. I have holiday vacation until january, so i can not help you exactly, but if you can right click to open formula window, then maybe - but i think PCM would work here ( based on sin, cos functions ).

Try something. Only sure variable is "index"
Link to comment
Share on other sites

Hi,
The point generator only allows "implicit" formulas
In the present case the counter should run from a start angle to an end angle,
with the direction of rotation changing after 180° of the angle range.
Such complex formulas must be calculated in the PreParameter. 1633_ff2ca95ea1eb9f3f7b77a053eb0ec2f1.docx

ZigZagCylinder.zip

Link to comment
Share on other sites

 Share

×
×
  • Create New...