new forms - pyramid and prism

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
TheNo1Odor
Posts: 7
Joined: Thu Jun 25, 2015 7:02 am

new forms - pyramid and prism

Post by TheNo1Odor »

I would like to see implemented the forms pyramid and prism.
Their base could be with three, four,five or more sides.
Image Image
Pyramids like in here: http://www.mathsisfun.com/geometry/pyramids.html or here: http://www.mathopenref.com/pyramid.html
and prisms like in here h[url]ttp://www.mathsisfun.com/geometry/prisms.html[/url] and in here: http://www.mathopenref.com/prism.html.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: new forms - pyramid and prism

Post by microelly2 »

Prisms are already in Part create Primitives.

pyramides - i have to recover my old workbench but for the first here is an example

Code: Select all


import math
from math import sqrt, pi, sin, cos, asin

def say(s):
		FreeCAD.Console.PrintMessage(str(s)+"\n")

def vieleck(anz,size,hoehe): # regelmaesiges vieleck berechnen
	list1=[]
	for p in range(anz):
		punkt=( size*cos(2*math.pi *p/anz),size*sin(2*math.pi*p/anz),hoehe)
		list1.append(punkt)
	#	say(punkt)
	
	p=0
	punkt=( size*cos(2*math.pi *p/anz),size*sin(2*math.pi*p/anz),hoehe)
	list1.append(punkt)
#	say(list1)
	return list1


def gen_pyramidenstumpf(count=8,size_bottom = 60, size_top=20, height=60):

	list1=vieleck(count,size_bottom,0)
	list2=vieleck(count,size_top,height)
	
	poly1 = Part.makePolygon( list1)
	poly2 = Part.makePolygon( list2)
	face1 = Part.Face(poly1)
	face2 = Part.Face(poly2)
	faceListe=[face1,face2]
	
	for i in range(len(list1)-1):
		liste3=[list1[i],list1[i+1],list2[i+1],list2[i],list1[i]]
		poly=Part.makePolygon(liste3)
		face = Part.Face(poly)
		faceListe.append(face)
	#	say(i);say(poly);say(faceListe)
	
	myShell = Part.makeShell(faceListe)   
	mySolid = Part.makeSolid(myShell)
	return mySolid


obj=App.ActiveDocument.addObject("Part::Feature","Pymf")
obj.Shape=gen_pyramidenstumpf(5,30,1,30)



TheNo1Odor
Posts: 7
Joined: Thu Jun 25, 2015 7:02 am

Re: new forms - pyramid and prism

Post by TheNo1Odor »

Thank you for pointing it out about the prism.

I had to do some experimentation with the final line to understand what the parameters mean (i do not know German):

Code: Select all

obj.Shape=gen_pyramidenstumpf(5,30,1,30)
And the pyramid is truncated...
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: new forms - pyramid and prism

Post by microelly2 »

it was a first answer.
To get an untracated pyramid I have to change the algorithm (I will do it)

parameters:

def gen_pyramidenstumpf(count=8,size_bottom = 60, size_top=20, height=60):
gen_pyramidenstumpf(5,30,1,30)

count - number of edged of the base regular polyeder
size bottom - diameter of the base face
size tog - diameter of the top face if you set it to 0.001 mm you will get nearliy a pyramit
height - z-dimension of the pyramid
Post Reply