FreeCAD Logo FreeCAD 1.0
  • Englisch Afrikaans Arabisch Weißrussisch Katalanisch Tschechisch Deutsch Griechisch Spanisch Spanisch Baskisch Finnisch Philippinisch Französisch Galicisch Kroatisch Ungarisch Indonesisch Italienisch Japanisch Kabylisch Koreanisch Litauisch Niederländisch Norwegisches Bokmål Polnisch Portugiesisch Portugiesisch Rumänisch Russisch Slowakisch Slowenisch Serbisch Schwedisch Türkisch Ukrainisch Valencianisch Vietnamesisch Chinesisch Chinesisch
  • Funktionen
  • Herunterladen
  • Blog
  • Dokumentation
    Inhaltsverzeichnis Erste Schritte Benutzerdokumentation Das FreeCAD-Handbuch Dokumentation der Arbeitsbereiche Python-Dokumentation Dokumentation der C++ Programmierung Anleitungen Häufig gestellte Fragen Datenschutzrichtlinie Über FreeCAD
  • Mitwirken
    Wie kann ich helfen Sponsor Einen Fehler melden Einen Pull Request durchführen Jobs und Finanzierung Richtlinien für Beiträge Entwicklerhandbuch Übersetzungen
  • Community
    Verhaltenskodex Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Kalender
  • ♥ Donate

Donate

$
SEPA-Informationen
Bitte richten Sie Ihre SEPA-Überweisung an:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Kreditinstitut: BNP Paribas Fortis
Adresse: Rue de la Station 64, 1360 Perwez, Belgium

While Stripe doesn't support monthly donations, you can still become a sponsor! Simply make a one-time donation equivalent to 12 months of support, and you'll gain access to the corresponding sponsoring tier. It's an easy and flexible way to contribute.

If you are not sure or not able to commit to a regular donation, but still want to help the project, you can do a one-time donation, of any amount.

Choose freely the amount you wish to donate one time only.

You can support FreeCAD by sponsoring it as an individual or organization through various platforms. Sponsorship provides a steady income for developers, allowing the FPA to plan ahead and enabling greater investment in FreeCAD. To encourage sponsorship, we offer different tiers, and unless you choose to remain anonymous, your name or company logo will be featured on our website accordingly.

from 1 USD / 1 EUR per month. You will not have your name displayed here, but you will have helped the project a lot anyway. Together, normal sponsors maintain the project on its feet as much as the bigger sponsors.

from 25 USD / 25 EUR per month. Your name or company name is displayed on this page.

from 100 USD / 100 EUR per month. Your name or company name is displayed on this page, with a link to your website, and a one-line description text.

from 200 USD / 200 EUR per month. Your name or company name and logo displayed on this page, with a link to your website and a custom description text. Companies that have helped FreeCAD early on also appear under Gold sponsors.

Instead of donating each month, you might find it more comfortable to make a one-time donation that, when divided by twelve, would give you right to enter a sponsoring tier. Don't hesitate to do so!

Choose freely the amount you wish to donate each month.

Please inform your forum name or twitter handle as a notein your transfer, or reach to us, so we can give you proper credits!

Hilbert-Kurve

Beschreibung
Dieses Makro erstellt eine Hilbert-Kurve in 2 oder 3 Dimensionen mit vielen Iterationen.

Versionsmakro : 1.2.0
Datum der letzten Änderung : 2021-02-13
FreeCAD version : 0.16 to 0.19
Herunterladen : Werkzeugleisten-Symbol
Autor: Simone Bignetti
Autor
Simone Bignetti
Herunterladen
Werkzeugleisten-Symbol
Links
Makros Rezepte
Wie man Makros installiert
Symbolleisten anpassen
Macro-Version
1.2.0
Datum der letzten Änderung
2021-02-13
FreeCAD-Version(s)
0.16 to 0.19
Standardverknüpfung
None
Siehe auch
None

Beschreibung

Dieses Makro erstellt eine Hilbert-Kurve in zwei oder drei Dimensionen mit vielen Iterationen.

Anwendung

  1. Das Makro in einem FreeCAD-Dokument starten.
  2. Im sich öffnenden Dialogfeld die Parameter für die Hilbert-Kurve auswählen:
    • Auswählen, ob die Kurve zweidimensional 2D oder dreidimensional 3D sein soll.
    • Die Anzahl der Iterationen angeben 1 . Achtung! Eine Erhöhung der Anzahl der Iterationen verlängert auch die Berechnungszeit.
    • Die Länge des Linienzugsegments angeben: 10.00 .
  3. Auf OK klicken, um den Linienzug zu erstellen, oder auf CANCEL, um das Makro zu beenden.
Der Hilbert-Linienzug in 3D und zwei Iterationen.
Der Hilbert-Linienzug in 3D und zwei Iterationen.

Man kann eine Hilbert-Kurve als Pfad für eine Part Ausformung verwenden, aber es ist besser, zuerst einen Radius auf den Linienzug anzuwenden, da sonst die Ausformung schlecht wird.

Der Linienzug einer Hilbert Curve mit einem Radius.
Der Linienzug einer Hilbert Curve mit einem Radius.

Um den richtigen Radius zu finden, sind möglicherweise einige Tests erforderlich. Dies hängt von der Länge der Kurvensegmente und der Form des Profils ab, das man ausführen möchte.

Ein Festkörper, der durch ausformen eines Kreises durch die Hilbert-Kurve erhalten wird.
Ein Festkörper, der durch ausformen eines Kreises durch die Hilbert-Kurve erhalten wird.

Skript

Werkzeugleisten-Symbol

Macro_HilbertCurve.FCMacro

# -*- coding: utf-8 -*-

# Copyright (c) 2020 Simone Bignetti, Gottolengo Italy (simone.b)
#
# This file is part of the FreeCAD CAx development system.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
# USA
#
# You can contact me by mail at simone.bignetti@linux.it

__Name__ = 'HilbertCurve'
__Comment__ = 'This macro creates an Hilbert curve wire in 2 or 3 dimensions with many iterations.'
__Author__  = 'Simone Bignetti'
__Version__ = '1.2.0'
__Date__    = '2020-12-29'
__License__ = 'GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999'
__Web__ = 'https://wiki.freecad.org/Macro_HilbertCurve'
__Wiki__ = 'https://wiki.freecad.org/Macro_HilbertCurve'
__Icon__ = 'https://wiki.freecad.org/images/6/69/Hilbert_curve_icon.png'
__Help__ = 'Choose the dimensions of the wire, the number of the iterations and the length of the wire segment.'
__Status__ = 'Stable'
__Requires__ = ''
__Communication__ = 'https://forum.freecad.org/viewtopic.php?f=22&t=53781'
__Files__ = 'HilbertCurve.svg'


# For the wire
import FreeCAD as app
import Draft

# For the gui
from PySide import QtGui, QtCore

class HilbertCurve:
    """The class of the Hilbert curve.
    
    By this class it's possible to create a wire
    of a fractal Hilbert curve with
    a fixed number of dimensions and iterations.
    """
    
    def __init__(self, dimensions, iterations):
        """Initialize the Hilbert curve.
        Args:
            iterations (int): iterations to use in constructing the curve
            dimensions (int): number of dimensions
        """

self.dimensions = dimensions
        self.iterations = iterations

# minimum and maximum distance along curve
        self.min_distance = 0
        self.max_distance = 2 ** (self.iterations * self.dimensions) - 1

# minimum and maximum coordinate value in any dimension
        self.min_coordinate = 0
        self.max_coordinate = 2 ** self.iterations - 1

# number of points
        self.number_of_points = 2 ** (self.iterations * self.dimensions)

def point_from_distance(self, distance):
        """Return a point in n-dimensional space given a distance along a the curve.
        Args:
            distance (int): integer distance along the curve
        Returns:
            point (iterable of ints): an n-dimensional vector of length dimensions where
            each component value is between 0 and 2**iterations-1.
        """

bit_string = format(distance, 'b').zfill(self.iterations * self.dimensions)  # zero filled binary distance
        point = [int(bit_string[i::self.dimensions], 2) for i in range(self.dimensions)]  # transpose of distance

# Gray decode: point = point xor (point / 2)
        gray = point[self.dimensions-1] >> 1
        for i in range(self.dimensions-1, 0, -1):
            point[i] ^= point[i-1]
        point[0] ^= gray

# Undo excess work
        q = 2
        while q != (2 << (self.iterations-1)):
            p = q - 1
            for i in range(self.dimensions-1, -1, -1):
                if point[i] & q:
                    # invert
                    point[0] ^= p
                else:
                    # exchange
                    gray = (point[0] ^ point[i]) & p
                    point[0] ^= gray
                    point[i] ^= gray
            q <<= 1

return point

def get_min_distance(self):
        """Return the minimum distance along the curve."""
        return self.min_distance

def get_max_distance(self):
        """Return the maximum distance along the curve."""
        return self.max_distance

def get_min_coordinate(self):
        """Return the minimum coordinate value in any dimension."""
        return self.min_coordinate

def get_max_coordinate(self):
        """Return the maximum coordinate value in any dimension."""
        return self.max_coordinate

def get_number_of_points(self):
        """Return the number of points in the curve."""
        return self.number_of_points

def get_points(self):
        """Return the list of points in the curve."""
        points = []
        for point_number in range(self.number_of_points):
            points.append(self.point_from_distance(point_number))
        return points

def __str__(self):
        return f"HilbertCurve(dimensions={self.dimensions}, iterations={self.iterations})"

def __repr__(self):
        return self.__str__()


class Hilbert_Dialog(QtGui.QDialog):
    """The dialog for the Hilbert curve
    
    This class opens in FreeCAD a dialog to input
    the number of dimensions and the number of iterations
    to create the Hilbert curve.
    OK creates the curve.
    CANCEL quit the macro.
    """

def __init__(self):
        super(Hilbert_Dialog, self).__init__()
        self.setupUi()

def setupUi(self):
        self.dimensions = 2
        self.iterations = 3

self.setGeometry(250, 250, 400, 300)  # Window definition
        self.setWindowTitle("Hilbert curve Macro")

titleLabel = QtGui.QLabel("Create an Hilbert curve in two or three dimensions")  # Title and subtitle
        titleFont = QtGui.QFont()
        titleFont.setBold(True)
        titleFont.setWeight(75)
        titleLabel.setFont(titleFont)
        subtitleLabel = QtGui.QLabel("This macro creates a wire in the draft workbench\nwith the shape of an Hilbert curve in two or three dimensions.\nFor example, you can use this wire as a sweep path.\nIt's recommended to apply a radius at the wire,\nin order to obtain a correct sweep generation.")
        titleBox = QtGui.QVBoxLayout()
        titleBox.addWidget(titleLabel)
        titleBox.addWidget(subtitleLabel)
        titleBox.insertStretch(-1)

dimensionsLabel = QtGui.QLabel("Number of dimensions: ")  # Number of dimensions
        self.twoDradioButton = QtGui.QRadioButton()
        self.twoDradioButton.setText("2D")
        self.twoDradioButton.setChecked(True)
        self.threeDradioButton = QtGui.QRadioButton()
        self.threeDradioButton.setText("3D")
        dimensionsBox=QtGui.QHBoxLayout()
        dimensionsBox.addWidget(dimensionsLabel)
        dimensionsBox.addWidget(self.twoDradioButton)
        dimensionsBox.addWidget(self.threeDradioButton)

iterationsLabel = QtGui.QLabel("Iterations:")  # Iterations  and length spins in a grid
        self.iterationsSpin = QtGui.QSpinBox()
        self.iterationsSpin.setMinimum(1)
        self.iterationsSpin.setMaximum(10)
        lengthLabel = QtGui.QLabel("Length:")
        self.lengthSpin = QtGui.QDoubleSpinBox()
        self.lengthSpin.setMinimum(1.0)
        self.lengthSpin.setMaximum(999999.000000000000000)
        self.lengthSpin.setValue(10.000000000000000)
        grid = QtGui.QGridLayout()
        grid.setSpacing(10)
        grid.addWidget(iterationsLabel, 1, 0)
        grid.addWidget(self.iterationsSpin, 1, 1)
        grid.addWidget(lengthLabel, 2, 0)
        grid.addWidget(self.lengthSpin, 2, 1)

okButton = QtGui.QPushButton("OK")  # Ok and Cancel Buttons at right bottom
        okButton.clicked.connect(self.onOkButton)
        cancelButton = QtGui.QPushButton("Cancel")
        cancelButton.clicked.connect(self.onCancelButton)
        buttonBox = QtGui.QHBoxLayout()
        buttonBox.addStretch()
        buttonBox.addWidget(okButton)
        buttonBox.addWidget(cancelButton)

vbox = QtGui.QVBoxLayout()
        vbox.addLayout(titleBox)
        vbox.addLayout(dimensionsBox)
        vbox.addLayout(grid)
        vbox.addLayout(buttonBox)
        vbox.setSpacing(30)
        vbox.insertStretch(1)
        self.setLayout(vbox)

self.show()

def onOkButton(self):
        if self.twoDradioButton.isChecked():
            dimensions = 2
        else:
            dimensions = 3
        iterations = self.iterationsSpin.value()
        length = self.lengthSpin.value()
        HC=HilbertCurve(dimensions, iterations)
        points = HC.get_points()
        pl = app.Placement()
        pl.Rotation.Q = (0.0, 0.0, 0.0, 1.0)
        pl.Base = app.Vector(0.0, 0.0, 0.0)
        vectors = []
        if dimensions == 2:
            for point in points:
                vectors.append(app.Vector(point[0]*length, point[1]*length, 0.0))
        else:
            for point in points:
                vectors.append(app.Vector(point[0]*length, point[1]*length, point[2]*length))
        wire = Draft.makeWire(vectors, placement=pl, closed=False, face=False, support=None)
        wire.Label = "Hilbert"
        Draft.autogroup(wire)
        self.close()

def onCancelButton(self):
        self.close()


hilbert_dialog = Hilbert_Dialog()
hilbert_dialog.exec()

Diese Seite wird abgerufen von https://wiki.freecad.org/Macro_HilbertCurve

Kontaktiere uns!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© Das FreeCAD-Team. Bildnachweis (von oben nach unten): ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

Dieses Projekt wird unterstützt von: , KiCad Services Corp. und andere Sponsoren

GitHubDiese Seite auf GitHub verbessern