Hey,
I am trying to find a python script to help me do the following:
I have a FreeCad line/ray from which i know the starting point and the direction where it points in degrees. Additionally, I have a wall (from an architectural project). So the line represents the viewing direction from a camera, with which I took a photo.
I would like to find a script that prints out the point, where the line meets the wall.
Does someone maybe have any idea on how to do that? Code examples are greatly appreciated, since i am very new to all this.
Thanks a lot!
Intersection Ray/Plane
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 10
- Joined: Mon Jan 06, 2020 1:43 pm
Re: Intersection Ray/Plane
hi
try Macro_WorkFeatures Points > Point 1/3 > Point=(Line,Face)
or this script (the line should touch the face(s))
mario
try Macro_WorkFeatures Points > Point 1/3 > Point=(Line,Face)
or this script (the line should touch the face(s))
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example for intersection of shape(Solid) & line(Edge)
# Usage: select a line and a solid, then run this macro
# http://www.forum.freecadweb.org/viewtopic.php?f=22&t=5456
import FreeCAD
import Part
s = FreeCADGui.Selection.getSelection()
if len(s) < 2:
print( "not enough objects selected - ", len(s))
else:
try:
s1 = s[0].Shape
s2 = s[1].Shape
cs = s1.common(s2)
if cs.Vertexes:
for v in cs.Vertexes:
point = App.ActiveDocument.addObject("Part::Vertex","Vertex")
point.Placement=Base.Placement(Base.Vector(v.Point),Base.Rotation(0.0000,0.0000,0.0000,1.0000))
print( "intersection point : ", v.Point)
except Exception:
print( "can't find an intersection point")
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
-
- Posts: 10
- Joined: Mon Jan 06, 2020 1:43 pm
Re: Intersection Ray/Plane
hi, thanks for the tips! Unfortunetly, even though i have a line and a plane crossing in one point, the script always says "can't find an intersection point". So that couldnt help.
I searched a lot and couldnt really find a helpful script. So that makes me think is there not an easy way to do that? In my project it should work without finding the points by hands, that is what my professor wants.
Anyone any other ideas? Thanks
I searched a lot and couldnt really find a helpful script. So that makes me think is there not an easy way to do that? In my project it should work without finding the points by hands, that is what my professor wants.
Anyone any other ideas? Thanks
Re: Intersection Ray/Plane
hi
give an example file with your objects for testing
mario
give an example file with your objects for testing
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
-
- Posts: 10
- Joined: Mon Jan 06, 2020 1:43 pm
Re: Intersection Ray/Plane
Basically i made a macro that shows the camera direction and then creates a wall where i can put the image as a texture. (25@001.01.Teil2.FCMacro)
Sorry, i experiment a lot xD
The orange line in the middle passes through the wall, thats where i want to know at which exact point that happens.
Thanks a lot
Re: Intersection Ray/Plane
hi
try this i adding "from FreeCAD import Base"
ps:do you want to change the macro name and supp @ (mozilla open the my hotmail)
mario
try this i adding "from FreeCAD import Base"
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example for intersection of shape(Solid) & line(Edge)
# Usage: select a line and a solid, then run this macro
# http://www.forum.freecadweb.org/viewtopic.php?f=22&t=5456
import FreeCAD
import Part
from FreeCAD import Base
s = FreeCADGui.Selection.getSelection()
if len(s) < 2:
print( "not enough objects selected - ", len(s))
else:
try:
s1 = s[0].Shape
s2 = s[1].Shape
cs = s1.common(s2)
if cs.Vertexes:
for v in cs.Vertexes:
point = App.ActiveDocument.addObject("Part::Vertex","Vertex")
point.Placement=Base.Placement(Base.Vector(v.Point),Base.Rotation(0.0000,0.0000,0.0000,1.0000))
print( "intersection point : ", v.Point)
except Exception:
print( "can't find an intersection point")
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
-
- Posts: 10
- Joined: Mon Jan 06, 2020 1:43 pm
Re: Intersection Ray/Plane
hi,
mario you are a genius, thank you so much, now it works you dont even know how much i appreciate your help that will help my project a lot! Much love
mario you are a genius, thank you so much, now it works you dont even know how much i appreciate your help that will help my project a lot! Much love