[Solved]:How to create a convex lens
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
[Solved]:How to create a convex lens
Hello,I'm working on a new raytracing workbench.
I want to create a concave or convex lens in my workbench.Can I use "Part::" to create in Python code?Or create lenses without using "Part::"?like this, it seems a little difficult
I want to create a concave or convex lens in my workbench.Can I use "Part::" to create in Python code?Or create lenses without using "Part::"?like this, it seems a little difficult
Last edited by xianyu on Wed Jul 06, 2022 7:24 am, edited 3 times in total.
Freecad novice, A Python enthusiast
-
- Posts: 84
- Joined: Mon May 16, 2022 10:35 am
Re: Question:How to create a convex lens
Hi,
Concave lens (like in the picture):
you could use Part_Cut between a Cylinder and two Spheres
1. In the Part WB create the primitives (Cylinder and Spheres)
2. Position the Spheres relative to the Cylinder with the desired overlap (probably only by adjusting the Z value of position)
3. Select the Cylinder (object to be kept), hold Ctrl and select one Sphere
4. Click on Part Cut
5. Select the Cut in the TreeView (object to be kept), hold Ctrl and select the second Sphere
6. Click on Part Cut
Convex lens:
you could use Part_Common between two overlapping Spheres:
1. In the Part WB create the primitives (Spheres)
2. Position the Spheres relative to eachother with the desired overlap (probably only by adjusting the Z value of position)
3. Select both Spheres by holding Ctrl
4. Click on Part Common
Kind regards,
Johannes
EDIT: Complemented answer with instructions for Convex lens due to confusion between the provided picture and the title of the post.
Concave lens (like in the picture):
you could use Part_Cut between a Cylinder and two Spheres
1. In the Part WB create the primitives (Cylinder and Spheres)
2. Position the Spheres relative to the Cylinder with the desired overlap (probably only by adjusting the Z value of position)
3. Select the Cylinder (object to be kept), hold Ctrl and select one Sphere
4. Click on Part Cut
5. Select the Cut in the TreeView (object to be kept), hold Ctrl and select the second Sphere
6. Click on Part Cut
Convex lens:
you could use Part_Common between two overlapping Spheres:
1. In the Part WB create the primitives (Spheres)
2. Position the Spheres relative to eachother with the desired overlap (probably only by adjusting the Z value of position)
3. Select both Spheres by holding Ctrl
4. Click on Part Common
Kind regards,
Johannes
EDIT: Complemented answer with instructions for Convex lens due to confusion between the provided picture and the title of the post.
Last edited by thyssentishman on Fri Jul 01, 2022 8:19 am, edited 1 time in total.
Re: Question:How to create a convex lens
Maybe there is a lens code in optics workbench
https://forum.freecad.org/viewtopic.php ... 0a16fd3123
https://forum.freecad.org/viewtopic.php ... 0a16fd3123
Re: Question:How to create a convex lens
Thank you for your reply.This is a very detailed way on how to create a Lens in a Part,this is very useful. But I am sorry that I did not describe the problem clearly.thyssentishman wrote: ↑Fri Jul 01, 2022 8:07 am Hi,
Concave lens (like in the picture):
you could use Part_Cut between a Cylinder and two Spheres
I want to do this in Python code, not in the Part workbench.
Freecad novice, A Python enthusiast
Re: Question:How to create a convex lens
Thank you for your reply.This helped me a lotjohnwang wrote: ↑Fri Jul 01, 2022 8:09 am Maybe there is a lens code in optics workbench
https://forum.freecad.org/viewtopic.php ... 0a16fd3123
Freecad novice, A Python enthusiast
-
- Posts: 84
- Joined: Mon May 16, 2022 10:35 am
Re: Question:How to create a convex lens
Makes sense, after all you posted in Python scripting and macros. My bad sorry.
You can do exactly the same that I explained in my previous reply in a script. Check out Part_API for creating the primitives and TopoShape_API for the boolean operations.
Make sure to import the Part library on your script.
Hope this helps.
Kind regards,
Johannes
Re: Question:How to create a convex lens
This is a very good suggestion and well worth a try.thyssentishman wrote: ↑Fri Jul 01, 2022 9:23 amYou can do exactly the same that I explained in my previous reply in a script. Check out Part_API for creating the primitives and TopoShape_API for the boolean operations.
Freecad novice, A Python enthusiast
-
- Posts: 84
- Joined: Mon May 16, 2022 10:35 am
Re: Question:How to create a convex lens
Check out these quick examples I made:
Concave Lens:
Convex Lens:
Kind regards,
Johannes
Concave Lens:
Code: Select all
import FreeCAD
import Part
doc = FreeCAD.newDocument()
def makeConcaveLens():
cylinder = Part.makeCylinder(5,10)
sphere1 = Part.makeSphere(5)
sphere2 = Part.makeSphere(5)
sphere2.Placement = FreeCAD.Placement(App.Vector(0.0000,0.0000,10.0000),App.Rotation(App.Vector(0.0000,0.0000,1.0000),0.0000))
cut1 = cylinder.cut(sphere1)
cut2 = cut1.cut(sphere2)
return cut2
concaveLens = doc.addObject("Part::Feature", "Concave Lens")
concaveLens.Shape = makeConcaveLens()
doc.recompute()
Code: Select all
import FreeCAD
import Part
doc = FreeCAD.newDocument()
def makeConvexLens():
sphere1 = Part.makeSphere(5)
sphere2 = Part.makeSphere(5)
sphere2.Placement = FreeCAD.Placement(App.Vector(0.0000,0.0000,5.0000),App.Rotation(App.Vector(0.0000,0.0000,1.0000),0.0000))
intersection = sphere1.common(sphere2)
return intersection
convexLens = doc.addObject("Part::Feature", "Convex Lens")
convexLens.Shape = makeConvexLens()
doc.recompute()
Johannes
Re: Question:How to create a convex lens
Thanks, your code is very useful.I try to implement the function of modifying the curvature in ComboView-Datathyssentishman wrote: ↑Fri Jul 01, 2022 9:40 am Check out these quick examples I made:
Kind regards,
Johannes
Code: Select all
convexLens.addProperty("App::PropertyFloat", "curv", "Shape", "central curvature")
Freecad novice, A Python enthusiast
-
- Posts: 84
- Joined: Mon May 16, 2022 10:35 am
Re: Question:How to create a convex lens
No problem glad I could help. If there is nothing else you need, please make sure to mark the topic as solved by editing the title of your first post and prepending [Solved].
Good luck!
Kind regards,
Johannes