Question continued from square to round

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Question continued from square to round

Post by jfc4120 »

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: English/United States (en_US)
Installed mods: 
  * Help 1.0.3

@johnwang

I don’t have a round to round; I have a general triangulation program.

You position as though you were inside duct looking at either direction of airflow or opposite.

And you set points on one end, then the other and it’s triangulated and laid out on another layer.

See images and I have captions explaining.

I am currently trying to do this code in freecad, but I am only on first section so far. I can't figure out how to rotate group to do another section.


Basiccad is easier to do things, you can do things like store a series of previous points.

Each new section triangulated starts at 0,0,0. In Basiccad you can reset origin. In python (Freecad) you are stuck with same origin, so it makes it harder.

Also see: https://forum.freecadweb.org/viewtopic. ... on#p611897
same code works on those. But some points have to be selected multiple times, depending on fitting (duct).

If you can figure out a rewrite that works in python that would be great.
Attachments
fcc1.png
fcc1.png (13.91 KiB) Viewed 1449 times
fcc2.png
fcc2.png (9.87 KiB) Viewed 1449 times
fcc5.png
fcc5.png (35.38 KiB) Viewed 1449 times
Bottom line and top curve are drawn in separate, not part of the program.
Bottom line and top curve are drawn in separate, not part of the program.
fcc8.png (8.38 KiB) Viewed 1449 times
Last edited by jfc4120 on Sun Feb 05, 2023 5:48 am, edited 1 time in total.
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Question continued from square to round

Post by johnwang »

I store a series of points like this:

Code: Select all

X=[]
Y=[]

...other code

X.append(aValue)
Y.append(bValue)
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Question continued from square to round

Post by onekk »

The point is to take the workflow of the original program and make a python equivalent.

From what I know Python is more powerful than basic, and probably you could leverage even some function present in FC ta make things more easily.

As example you could determine intersections points of lines and other things simply invoking a method or obtain distance from two points (Vectors) dimply using an appropriate method.

All without using mathematical solutions but using geometrical solutions.

And many more.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Question continued from square to round

Post by johnwang »

What is the value of SYS(1)?

and what the value of that point. There are SYS(1) of them.

Code: Select all

FOR J = 1 TO SYS(1)
A = A + 1
CTR = CTR + 1
POINTVAL XA YA ZA A
AX(A) = XA
AY(A) = YA
AZ(A) = ZA
NEXT
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Question continued from square to round

Post by jfc4120 »

Sys 1 is the number of points currently set.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Question continued from square to round

Post by edwilliams16 »

User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Question continued from square to round

Post by johnwang »

jfc4120 wrote: Sun Aug 14, 2022 4:01 am Sys 1 is the number of points currently set.
So, need to select some points?

Then hard to test this code.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Question continued from square to round

Post by jfc4120 »

@johnwang here is where I'm at so far in testing, I am at one section at a time. I am still trying to figure out the looping, rotating, etc like I did in Basiccad.

Code so far:

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD, FreeCADGui
import Draft
import math
# from math import cos, sin, radians
from PySide import QtGui

convert = 25.4

Vector, Placement = App.Vector, App.Placement
doc = App.ActiveDocument


def line_length(x1=0, y1=0, z1=0, length=10, angle=0):
    x2 = x1 + length * math.cos(math.radians(angle))
    y2 = y1 + length * math.sin(math.radians(angle))
    z2 = z1
    Draft.makeWire([Vector(x1, y1, z1), Vector(x2, y2, z2)])


def coord(x1=0, y1=0, z1=0, length=10, angle=0):
    x2 = x1 + length * math.cos(math.radians(angle))
    #x2 = x2 * convert
    y2 = y1 + length * math.sin(math.radians(angle))
    #y2 = y2 * convert
    z2 = z1
    #z2 = z2 * convert
    coo = [x2, y2, z2]
    return coo


# def coord(x1=0, y1=0, z1=0, length=10, angle=0):
#    x2 = x1 + length * math.cos(math.radians(angle))
#    y2 = y1 + length * math.sin(math.radians(angle))
#    z2 = z1
#    coo = [x2, y2]
#    return coo

start_point = Vector(0, 0, 0)
selX = FreeCADGui.Selection.getSelectionEx()
PrintMsg = FreeCAD.Console.PrintMessage
PrintMsg("Objects selected:\n")
KOUNT = 0
# added
for sel in selX:
    KOUNT = KOUNT + 1
    v = sel.Object.Shape
    X = v.Point.x * .039370078
    Y = v.Point.y * .039370078
    Z = v.Point.z * .039370078
    if KOUNT == 1:
        multlist = [[X, Y, Z]]
    if KOUNT > 1:
        multlist.append([X, Y, Z])

# added

YTMP = multlist[2][1]
print('ytmp', YTMP)

LINE02 = math.sqrt(((multlist[0][0] - multlist[2][0])) ** 2 + ((multlist[0][1] - multlist[2][1])) ** 2 + ((multlist[0][2] - multlist[2][2])) ** 2)
LINE12 = math.sqrt(((multlist[1][0] - multlist[2][0])) ** 2 + ((multlist[1][1] - multlist[2][1])) ** 2 + ((multlist[1][2] - multlist[2][2])) ** 2)
LINE01 = math.sqrt(((multlist[0][0] - multlist[1][0])) ** 2 + ((multlist[0][1] - multlist[1][1])) ** 2 + ((multlist[0][2] - multlist[1][2])) ** 2)

A1 = math.acos(((abs(LINE02) ** 2 + abs(LINE12) ** 2 - abs(LINE01) ** 2) / (2 * LINE02 * LINE12)))
# print('line01', LINE01)
A1 = A1 * (180 / 3.1459)
# print('A1', A1)

LINE32 = math.sqrt(((multlist[3][0] - multlist[2][0])) ** 2 + ((multlist[3][1] - multlist[2][1])) ** 2 + ((multlist[3][2] - multlist[2][2])) ** 2)
LINE13 = math.sqrt(((multlist[1][0] - multlist[3][0])) ** 2 + ((multlist[1][1] - multlist[3][1])) ** 2 + ((multlist[1][2] - multlist[3][2])) ** 2)

A2 = math.acos(((abs(LINE12) ** 2 + abs(LINE32) ** 2 - abs(LINE13) ** 2) / (2 * LINE12 * LINE32)))
A2 = A2 * (180 / 3.1459)

x1 = y1 = z1 = 0  # Edit coordinate origin
length = LINE02
length = length * 25.4
angle = 90
line_length(x1, y1, z1, length, angle)
clist1 = coord(x1, y1, z1, length, angle)

x1 = y1 = z1 = 0  # Edit coordinate origin
length = LINE12
length = length * 25.4
angle = 90 + A1
line_length(x1, y1, z1, length, angle)
clist2 = coord(x1, y1, z1, length, angle)

print('clist2x:', clist2[0])

x1 = y1 = z1 = 0  # Edit coordinate origin
length = LINE32
length = length * 25.4
angle = 90 + A1 + A2
line_length(x1, y1, z1, length, angle)
clist3 = coord(x1, y1, z1, length, angle)
print('clist3', clist3)
Draft.makeWire([Vector(clist2[0], clist2[1], clist2[2]), Vector(clist3[0], clist3[1], clist3[2])])

Eventually I need to figure out how to rotate just a group (Layer in designcad). Yes I know I can use mesh, but I want to triangulate. It's a hobby also converting basiccad to python. And fun. And hard also as python and freecad does things different.

And some images:
Attachments
tri_test1.png
tri_test1.png (7.55 KiB) Viewed 1141 times
tri_test2.png
tri_test2.png (6.94 KiB) Viewed 1141 times
tri_test3.png
tri_test3.png (19.84 KiB) Viewed 1141 times
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: Question continued from square to round

Post by johnwang »

I like the other way. Just specify a few parameters, then draw the flat pattern directly. No need to draw the geometry and no need to select points.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Question continued from square to round

Post by jfc4120 »

@johnwang I did the triangulation program in python. Needs some cleanup (many print statements) for testing Plus I am going to test more fittings.

All is laid out from inside fitting.
Attachments
tri.png
tri.png (2.69 KiB) Viewed 912 times
tri2.png
tri2.png (6.8 KiB) Viewed 912 times
Post Reply