Macro Draft Circle 3 Points 3D/fr: Difference between revisions
Renatorivo (talk | contribs) (Created page with "Cette macro crée un cercle circonscrit sur 3 points sélectionnés dans l'espace. Les points peuvent être des objets tels que des points, cubes, cylindres . . .") |
(Updating to match new version of source page) |
||
(20 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
⚫ | |||
{{Macro/fr|Icon=Macro_Draft_Circle_3_Points|Name=Macro_Draft_Circle_3_Points_3D|Name/fr=Macro_Draft_Circle_3_Points_3D|Description=Crée un cercle sur 3 points dans l'espace.|Author=galou_breizh}} |
|||
{{Macro/fr |
|||
|Name=Macro_Draft_Circle_3_Points_3D |
|||
|Icon=Macro_Draft_Circle_3_Points.png |
|||
|Description=Crée un cercle sur 3 points dans l'espace. |
|||
|Author=galou_breizh |
|||
|Version=01.00 |
|||
|Date=2013-03-16 |
|||
|FCVersion=All |
|||
|Download=[https://www.freecadweb.org/wiki/images/1/10/Macro_Draft_Circle_3_Points.png ToolBar Icon] |
|||
}} |
|||
==Description== |
|||
Cette macro crée un cercle circonscrit sur 3 points sélectionnés dans l'espace. Les points peuvent être des objets tels que des points, cubes, cylindres . . . |
Cette macro crée un cercle circonscrit sur 3 points sélectionnés dans l'espace. Les points peuvent être des objets tels que des points, cubes, cylindres . . . |
||
[[File:Macro_Draft_Circle_3_Points_3D.png|480px]] |
[[File:Macro_Draft_Circle_3_Points_3D.png|480px]] |
||
{{clear}} |
|||
== |
==Utilisation== |
||
Select 3 points, or forms in the 3D view and run the macro.<br /> |
|||
Sélectionnez 3 points, ou formes dans la vue 3D, et démarrez la macro. |
|||
If the shape is a line, the coordinate will be the center of the line. |
|||
Si la forme est une ligne, les coordonnées seront le centre de la ligne. |
|||
==Limitations== |
|||
L'ordre de sélection des formes peur influencer l'angle "'''AXIS'''" et inverser l'inclinaison du cercle. Dans ce cas, inverser ou changer l'ordre de sélection des formes. |
|||
Les coordonnées '''X,Y,Z''' de valeur '''0''' ou un alignement ne permettant pas le calcul, peut renvoyer un erreur de division par zero, et traduit par "'''The three points are aligned'''" |
|||
⚫ | |||
ToolBar Icon [[Image:Macro_Draft_Circle_3_Points.png]] |
|||
===Limits=== |
|||
The order of selection of fear forms influencing the '''AXIS''' angle and reverse the inclination of the circle. In this case, reverse or change the order of selection of the shapes.<br /> |
|||
The coordinates '''X, Y, Z''' of value '''0''' or alignment not allowing not calculating, can return a division by zero error, and translated as "The three points are aligned" |
|||
'''Macro_Draft_Circle_3_Points_3D.FCMacro''' |
|||
⚫ | |||
{{MacroCode|code= |
|||
<syntaxhighlight> |
|||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||
# Create a circle from 3 points selected on the X, Y, Z map |
# Create a circle from 3 points selected on the X, Y, Z map |
||
# 04/03/2013 |
# 04/03/2013 |
||
# From |
# From https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates_from_cross-_and_dot-products |
||
# Also see : https://math.stackexchange.com/questions/2658318/how-to-find-the-circumcenter-of-a-triangle-and-the-length-of-the-corresponding-r |
|||
# O=R/2S*(acosα⋅A+bcosβ⋅B+ccosγ⋅C) ; R is circumradius, S is area of triangle |
|||
# 08/08/2014 PyQt4 and PySide |
|||
#OS: Windows Vista |
|||
#Word size: 32-bit |
|||
#Version: 0.14.3700 (Git) |
|||
#Branch: releases/FreeCAD-0-14 |
|||
#Hash: 32f5aae0a64333ec8d5d160dbc46e690510c8fe1 |
|||
#Python version: 2.6.2 |
|||
#Qt version: 4.5.2 |
|||
#Coin version: 3.1.0 |
|||
#SoQt version: 1.4.1 |
|||
#OCC version: 6.5.1 |
|||
try: |
|||
import PyQt4 |
|||
⚫ | |||
except Exception: |
|||
import PySide |
|||
from PySide import QtCore, QtGui |
|||
from math import pi, asin |
from math import pi, asin |
||
import Draft, FreeCAD, FreeCADGui |
import Draft, FreeCAD, FreeCADGui |
||
from FreeCAD import Base |
from FreeCAD import Base |
||
⚫ | |||
def errorDialog(msg): |
def errorDialog(msg): |
||
Line 94: | Line 130: | ||
errorDialog("Select 3 points and repeat\n") |
errorDialog("Select 3 points and repeat\n") |
||
}} |
|||
</syntaxhighlight> |
|||
⚫ |
Latest revision as of 16:56, 20 January 2021
Description |
---|
Crée un cercle sur 3 points dans l'espace. Version macro : 01.00 Date dernière modification : 2013-03-16 Version FreeCAD : All Téléchargement : ToolBar Icon Auteur: galou_breizh |
Auteur |
galou_breizh |
Téléchargement |
ToolBar Icon |
Liens |
Page des macros Comment installer une macro Comment créer une barre d'outils |
Version Macro |
01.00 |
Dernière modification |
2013-03-16 |
Version(s) FreeCAD |
All |
Raccourci clavier |
None |
Voir aussi |
None |
Description
Cette macro crée un cercle circonscrit sur 3 points sélectionnés dans l'espace. Les points peuvent être des objets tels que des points, cubes, cylindres . . .
Utilisation
Sélectionnez 3 points, ou formes dans la vue 3D, et démarrez la macro.
Si la forme est une ligne, les coordonnées seront le centre de la ligne.
Limitations
L'ordre de sélection des formes peur influencer l'angle "AXIS" et inverser l'inclinaison du cercle. Dans ce cas, inverser ou changer l'ordre de sélection des formes.
Les coordonnées X,Y,Z de valeur 0 ou un alignement ne permettant pas le calcul, peut renvoyer un erreur de division par zero, et traduit par "The three points are aligned"
Script
Macro_Draft_Circle_3_Points_3D.FCMacro
# -*- coding: utf-8 -*- # Create a circle from 3 points selected on the X, Y, Z map # 04/03/2013 # From https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates_from_cross-_and_dot-products # Also see : https://math.stackexchange.com/questions/2658318/how-to-find-the-circumcenter-of-a-triangle-and-the-length-of-the-corresponding-r # O=R/2S*(acosα⋅A+bcosβ⋅B+ccosγ⋅C) ; R is circumradius, S is area of triangle # 08/08/2014 PyQt4 and PySide #OS: Windows Vista #Word size: 32-bit #Version: 0.14.3700 (Git) #Branch: releases/FreeCAD-0-14 #Hash: 32f5aae0a64333ec8d5d160dbc46e690510c8fe1 #Python version: 2.6.2 #Qt version: 4.5.2 #Coin version: 3.1.0 #SoQt version: 1.4.1 #OCC version: 6.5.1 try: import PyQt4 from PyQt4 import QtCore, QtGui except Exception: import PySide from PySide import QtCore, QtGui from math import pi, asin import Draft, FreeCAD, FreeCADGui from FreeCAD import Base def errorDialog(msg): # Create a simple dialog QMessageBox # The first argument indicates the icon used: one of QtGui.QMessageBox.{NoIcon, Information, Warning, Critical, Question} diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg) diag.setWindowModality(QtCore.Qt.ApplicationModal) diag.exec_() def affiche(x,y,z,r,angle): diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,u"Coordinates",u"Coordinate X : "+str(x)+"\r\n"+u"Coordinate Y : "+str(y)+"\n"+u"Coordinate Z : "+str(z)+"\nRadius\t : "+str(r)+"\nAngle\t : "+str(angle)) diag.setWindowModality(QtCore.Qt.ApplicationModal) diag.setWindowModality(QtCore.Qt.NonModal) diag.exec_() # objects selected sel = FreeCADGui.Selection.getSelection() # If there are 3 selected points so... if len(sel)==3 : # Assignment of variables P1 = sel[0].Shape.BoundBox.Center P2 = sel[1].Shape.BoundBox.Center P3 = sel[2].Shape.BoundBox.Center P1P2 = (P2 - P1).Length P2P3 = (P3 - P2).Length P3P1 = (P1 - P3).Length # Circle radius. l = ((P1 - P2).cross(P2 - P3)).Length try: #if l < 1e-8: # errorDialog("The three points are aligned") r = P1P2 * P2P3 * P3P1 / 2 / l except: errorDialog("The three points are aligned") else: # Sphere center. a = P2P3**2 * (P1 - P2).dot(P1 - P3) / 2 / l**2 b = P3P1**2 * (P2 - P1).dot(P2 - P3) / 2 / l**2 c = P1P2**2 * (P3 - P1).dot(P3 - P2) / 2 / l**2 P1.multiply(a) P2.multiply(b) P3.multiply(c) PC = P1 + P2 + P3 # Creation of a circle pl = Base.Placement() v = (P1 - P2).cross(P3 - P2) v.normalize() axis = Base.Vector(0, 0, 1).cross(v) angle = asin(axis.Length) * 180 / pi axis.normalize() pl = Base.Placement(PC, axis, angle) Draft.makeCircle(r, placement=pl, face=False, support=None) # Displays the result in the windows affiche((PC.x),(PC.y),(PC.z),r,angle) # Displays the result in the FreeCAD report view #FreeCAD.Console.PrintMessage("Coordinate X : "+str(PC.x)+"\n") #FreeCAD.Console.PrintMessage("Coordinate Y : "+str(PC.y)+"\n") #FreeCAD.Console.PrintMessage("Coordinate Z : "+str(PC.z)+"\n") #FreeCAD.Console.PrintMessage("Radius : "+str(r)+"\n") #FreeCAD.Console.PrintMessage("Angle : "+str(angle)+"\n") else: # If the condition is not met, repeat #FreeCAD.Console.PrintError("Select 3 points and repeat\n") errorDialog("Select 3 points and repeat\n")