Also ich habe momentan ein Problem, Ich versuche NUR die Projektion auf einem Körper darzustellen. Tipps und Ansätze wären echt genial.
Danke im voraus.
Projection darstellen (NUR Projektion)
Also gut__deets__ hat geschrieben: Dienstag 17. September 2019, 07:45 Mit dieser Beschreibung kann ich nichts anfangen. Kannst du da mal ausholen?
Ich hoffe, dass es dir reicht wenn ich meinen bisherigen code schicke:
from OCC.Display.SimpleGui import init_display
import numpy as np
display, start_display, add_menu, add_function_to_menu = init_display()
EPSILON = 1e-12
def displayMyShape(s):
try:
display.EraseAll()
if s is None:
return
display.DisplayShape(s)
display.View_Iso()
display.FitAll()
except Exception as e:
print(e)
def sagOfSphere(r, h):
"""Returns the sag of a sphere with the center on the optical axis
Args:
r (float): radius of the sphere
h (float or numpy array of float): radial position with respect to the center
Returns:
Sag value(s) at the defined radial position
"""
# catch the special case r=0.0 for which the real value is inf
if abs(r) < EPSILON:
r = np.inf
if np.max(np.abs(h)) <= np.abs(r):
return r - np.sign(r) * np.sqrt(r ** 2 - h ** 2)
return 0.0
def makeBox():
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
s = BRepPrimAPI_MakeBox(20, 20, 0.01).Shape()
return s
def makeCone():
from OCC.BRepPrimAPI import BRepPrimAPI_MakeCone
s = BRepPrimAPI_MakeCone(100, 50, 100).Shape() # (radius unten, radius oben, hoehe)
return s
def makeCylinder():
from OCC.BRepPrimAPI import BRepPrimAPI_MakeCylinder
s = BRepPrimAPI_MakeCylinder(50, 200).Shape() # (radius, hoehe)
return s
def makeHalfSpace():
# from OCC.BRepPrimAPI import BRepPrimAPI_MakeHalfSpace
# s = BRepPrimAPI_MakeHalfSpace(face, point)
return None
def makePolygon():
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakePolygon
from OCC.gp import gp_Pnt
polygon = BRepBuilderAPI_MakePolygon()
polygon.Add(gp_Pnt(0., 0., 0.))
polygon.Add(gp_Pnt(20., 0., 0.))
polygon.Add(gp_Pnt(20., 20., 0.))
polygon.Add(gp_Pnt(0., 20., 0.))
polygon.Close()
s = polygon.Wire()
return s
def makePolygon2():
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakePolygon
from OCC.gp import gp_Pnt
polygon = BRepBuilderAPI_MakePolygon()
polygon.Add(gp_Pnt(0., 0., 0.))
polygon.Add(gp_Pnt(20., 0., 0.))
polygon.Close()
s = polygon.Wire()
return s
def makePrism():
from OCC.BRepPrimAPI import BRepPrimAPI_MakePrism
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from OCC.gp import gp_Vec
polygon = makePolygon() # TopoDS_Wire
face = BRepBuilderAPI_MakeFace(polygon).Face() # TopoDS_Face
vector = gp_Vec(0.0, 0.0, 20.0)
s = BRepPrimAPI_MakePrism(face, vector).Shape()
return s
def makeSphere():
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
s = BRepPrimAPI_MakeSphere(123.12).Shape()
return s
def makeTorus():
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
s = BRepPrimAPI_MakeTorus(100, 50).Shape()
return s
def makeRevol(hMax, radius):
from OCC.BRepPrimAPI import BRepPrimAPI_MakeRevol
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge
from OCC.gp import gp_Ax1, gp_Pnt, gp_Dir
from OCC.GC import GC_MakeArcOfCircle
pointFrontAxis = gp_Pnt(0.0, 0.0, 0.0)
pointFrontHMaxHalf = gp_Pnt(0.0, hMax / 2, sagOfSphere(radius, hMax / 2))
pointFrontHMax = gp_Pnt(0.0, hMax, sagOfSphere(radius, hMax))
frontSegment = GC_MakeArcOfCircle(pointFrontAxis, pointFrontHMaxHalf, pointFrontHMax)
frontEdge = BRepBuilderAPI_MakeEdge(frontSegment.Value())
surfaceWire = BRepBuilderAPI_MakeWire()
surfaceWire.Add(frontEdge.Edge())
surfaceFace = BRepBuilderAPI_MakeFace(surfaceWire.Wire()).Face()
revolveAxis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
angle = np.pi * 2
s = BRepPrimAPI_MakeRevol(surfaceFace, revolveAxis, angle).Shape()
return s
def makeProjection():
from OCC.BRepOffsetAPI import BRepOffsetAPI_NormalProjection
from OCC.BRepAlgoAPI import BRepAlgoAPI_Common, BRepAlgoAPI_Cut
surfaceShape = makeRevol(40, 100)
boxcurve = makeBox()
proj = BRepOffsetAPI_NormalProjection(surfaceShape)
proj.Add(boxcurve)
proj.Build()
proj.IsDone()
display.EraseAll()
display.DisplayShape(surfaceShape)
# display.DisplayShape(polygonCurve)
display.DisplayShape(proj.Shape())
display.View_Iso()
display.FitAll()
def makeProjection2():
from OCC.BRepOffsetAPI import BRepOffsetAPI_NormalProjection
from OCC.BRepAlgoAPI import BRepAlgoAPI_Common, BRepAlgoAPI_Cut
surfaceShape = makeRevol(40, 100)
polygoncurve = makePolygon()
proj = BRepOffsetAPI_NormalProjection(surfaceShape)
proj.Add(polygoncurve)
proj.Build()
proj.Add()
proj.IsDone()
display.EraseAll()
# display.DisplayShape(polygonCurve)
display.DisplayShape(proj.Shape())
display.View_Iso()
display.FitAll()
def displaypolygon2():
displayMyShape(makePolygon2())
def makecone():
from OCC.BRepPrimAPI import BRepPrimAPI_MakeCone
s = BRepPrimAPI_MakeCone(50, 100, 50).Shape()
return s
def displayBox():
displayMyShape(makeBox())
def displayCylinder():
displayMyShape(makeCylinder())
def displayCone():
displayMyShape(makeCone())
def displayHalfSpace():
displayMyShape(makeHalfSpace())
def displayPolygon():
displayMyShape(makePolygon())
def displayPrism():
displayMyShape(makePrism())
def displayProjection():
displayMyShape(makeProjection())
def displaySphere():
displayMyShape(makeSphere())
def displayTorus():
displayMyShape(makeTorus())
def displayRevol():
displayMyShape(makeRevol(40, 100))
def displayCone2():
displayMyShape(makecone())
add_menu('simple test')
add_function_to_menu('simple test', displayBox)
add_function_to_menu('simple test', displayCylinder)
add_function_to_menu('simple test', displayCone)
add_function_to_menu('simple test', displayHalfSpace)
add_function_to_menu('simple test', displayPolygon)
add_function_to_menu('simple test', displayPrism)
add_function_to_menu('simple test', displaySphere)
add_function_to_menu('simple test', displayTorus)
add_function_to_menu('simple test', displayRevol)
add_function_to_menu('simple test', makeProjection)
add_function_to_menu('simple test', makeProjection2)
add_function_to_menu('simple test', displaypolygon2)
add_menu('Von Raphael')
add_function_to_menu('Von Raphael', displayCone2)
display.View_Iso()
display.FitAll()
# display loop
start_display()
Projektion 2 ist das woran ich gerade arbeite.
Nein. Das reicht nicht. Du wirst dir schon ein bisschen Muehe machen muessen zu erklaeren, was du da mit welchen Softwarepaketen machst. Und was dein konkretes Problem ist, also Fehlermeldungen oder Verhalten, dass nicht ist, wie gedacht. Und dabei bitte auch die Code-Tags (</>-Knopf) benutzen, denn so ist das nicht zu entziffern.