Giter Club home page Giter Club logo

geometry3d's Introduction

Geometry3D

About Geometry3D

Geometry3D is a simple python computational geographics library written in python. This library focuses on the functions and lacks efficiency which might be improved in future version.

Core Features

  • Basic 3D Geometries: Point, Line, Plane, Segment, Convex Polygon and Convex Polyhedron.
  • Simple Object like Cubic, Sphere, Cylinder, Cone, Rectangle, Parallepiped, Parallogram and Circle.
  • Basic Attributes Of Geometries: length, area, volume.
  • Basic Relationships And Operations Between Geometries: move, angle, parallel, orthogonal, intersection.
  • Overload Build-In Functions Such As __contains__, __hash__, __eq__, __neg__.
  • A Naive Renderer Using matplotlib.

pic1

pic2

pic3

pic4

Some of the code comes from sgl whose author is really humorous.

Requirements

  • Python 3
  • No additional third-party library is required, it's written in pure python and standard library.
  • Matplotlib is needed if you want to use the renderer.

Documentation

Documentation Status

Installation

pip install Geometry3D

Test

Unit Tests

python run_tests.py

Tests

Run .py files under g3d_tests folder. For example:

python g3d_tests/test1.py

Usage

See Documentations

Change Log

changelog.md

License

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Contact

[email protected]

geometry3d's People

Contributors

gouminghao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

geometry3d's Issues

Operations on moved segment still use its original position

After moving a Segment by (0, 0, -1), the "in" and "intersection" operations still take the original position into account.

Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Geometry3D.version
'0.2.4'

s = Segment(Point(0, 0, 1), Point(2, 0, 1))
s.move(-z_unit_vector())
Segment(Point(0, 0, 0), Point(2, 0, 0))
s
Segment(Point(0, 0, 0), Point(2, 0, 0))
s2 = Segment(Point(0, 0, 0), Point(2, 0, 0))
s == s2
True
Point(1, 0, 0) in s2
True
Point(1, 0, 0) in s
False # Should return True
Point(1, 0, 1) in s
True # Should return False
ground = Plane(origin(), x_unit_vector(), y_unit_vector())
print(intersection(s2, ground))
Segment(Point(0, 0, 0), Point(2, 0, 0))
print(intersection(s, ground))
None # Should return the segment

This may be caused by a failure to move the "line" attribute accordingly:

s.line
Line(sv=Vector(0, 0, 1),dv=Vector(2, 0, 0))
s2.line
Line(sv=Vector(0, 0, 0),dv=Vector(2, 0, 0))

maybe a bug

When I execute the code below the program has an error

from Geometry3D import *
circle = Circle(Point(503.967529, 0, 370.521179),y_unit_vector(),400)
segment = Segment(Point(-353.2565, 0, -68.26225), Point(721.19, 0, 477.95))
print(circle.intersection(segment))

Hope you can tell me what is causing this problem
image

intersection of convex polygons sometime works fine and sometime fails

Hi
Thank you for the beautiful library.

When I run this code:
from Geometry3D import *

poly1=Sphere(Point(15.592607258702628, -66.15776443481445, 32.0),10,n1=7,n2=3)
poly2=Cylinder(Point(229.78870794537943, -64.86530276807025, 32.0),10,Vector(Point(229.78870794537943, -64.86530276807025, 32.0),Point(214.4889864671277, -64.95762145752087, 32.0)),10)

print(intersection(poly1,poly2))

I get the following output options:

  • ValueError: Convex Check Fails Because Point(17.840763238923472, -70.82610843057509, 23.521216889812855) Is Not On Plane(Point(15.592607250905829, -66.1577644285967, 22.000000002672117), Vector(0.0018647292618591013, -0.30901128616936524, -0.9510565429062221))
  • ValueError: Convex Check Fails Because Point(13.34985261467274, -70.81489244040448, 23.508768079903675) Is Not On Plane(Point(15.59260723547124, -66.15776444011686, 22.000000006384916), Vector(-0.0018645713266517239, 0.3090114447166194, 0.9510564917016842))
  • ValueError: Convex Check Fails Because Point(15.59260723547124, -66.15776444011686, 22.000000006384916) Is Not On Plane(Point(17.840763238923472, -70.82610843057509, 23.521216889812855), Vector(0.0018645699754517861, -0.30901136992221073, -0.9510565160060707))
  • None

It's strange, but the geometrical objects not even close:
Figure_1

Please, help

Extracting point information from different types of geometry

I was wondering if it is possible to extract the information from for instance a ConvexPolyhedron. I can print it and get "ConvexPolyhedron({Point(0, 3, 3), Point(3, 0, 0), Point(3, 3, 0), Point(0, 3, 0), Point(3, 0, 3), Point(0, 0, 3), Point(0, 0, 0), Point(3, 3, 3)})". However, I wish to have a numpy array with the points in it. Is there a way to do this?

Subtraction?

Would it be possible to have 3D polygon's subtracting from each other?

Bug detected

Hello when I calculate the intersection between these two polyhedron:
a = [ConvexPolygon((Point(234.9075469970703, 178.4456329345703, -0.0), Point(20.74983215332029, 225.9232635498047, 190.0), Point(8.035964965820328, 228.74185180664062, 190.0))), ConvexPolygon((Point(12.42473398461375, 244.4606612527466, 190.0000072746582), Point(25.138601658898136, 241.6420728879935, 190.0000072746582), Point(239.29632568359352, 194.1644439697266, 2.0726259984083645e-13))), ConvexPolygon((Point(20.74983215332029, 225.9232635498047, 190.0), Point(25.138601658898136, 241.6420728879935, 190.0000072746582), Point(12.42473398461375, 244.4606612527466, 190.0000072746582), Point(8.035964965820328, 228.74185180664062, 190.0))), ConvexPolygon((Point(239.29632568359352, 194.1644439697266, 2.0726259984083645e-13), Point(25.138601658898136, 241.6420728879935, 190.0000072746582), Point(20.74983215332029, 225.9232635498047, 190.0), Point(234.9075469970703, 178.4456329345703, -0.0))), ConvexPolygon((Point(234.9075469970703, 178.4456329345703, -0.0), Point(8.035964965820328, 228.74185180664062, 190.0), Point(12.42473398461375, 244.4606612527466, 190.0000072746582), Point(239.29632568359352, 194.1644439697266, 2.0726259984083645e-13)))]#[ConvexPolygon((Point(234.0, 178.0, 0.0), Point(19.999999999999993, 224.99999999999997, 190.0), Point(7.9999999999999725, 228.0, 190.0))), ConvexPolygon((Point(12.999999999999918, 243.99999999999997, 190.0), Point(24.999999999999993, 240.99999999999997, 190.0), Point(239.0000000000007, 193.99999999999983, -6.173231218204781e-13))), ConvexPolygon((Point(19.999999999999993, 224.99999999999997, 190.0), Point(24.999999999999993, 240.99999999999997, 190.0), Point(12.999999999999918, 243.99999999999997, 190.0), Point(7.9999999999999725, 228.0, 190.0))), ConvexPolygon((Point(234.0, 178.0, 0.0), Point(239.0000000000007, 193.99999999999983, -6.173231218204781e-13), Point(24.999999999999993, 240.99999999999997, 190.0), Point(19.999999999999993, 224.99999999999997, 190.0))), ConvexPolygon((Point(234.0, 178.0, 0.0), Point(7.9999999999999725, 228.0, 190.0), Point(12.999999999999918, 243.99999999999997, 190.0), Point(239.0000000000007, 193.99999999999983, -6.173231218204781e-13)))]

b = [ConvexPolygon((Point(236.5274658203125, 184.2475128173828, 0.0), Point(-105.78327941894531, 343.14288330078125, 190.0), Point(-112.74012756347656, 346.37213134765625, 183.30928039550778))), ConvexPolygon((Point(-109.73899495224315, 357.12103180010325, 183.30928773788403), Point(-102.7821465290583, 353.891783623882, 190.0000076103702), Point(239.52861022949182, 194.9963989257814, 1.807429067882295e-13))), ConvexPolygon((Point(-102.7821465290583, 353.891783623882, 190.0000076103702), Point(-109.73899495224315, 357.12103180010325, 183.30928773788403), Point(-112.74012756347656, 346.37213134765625, 183.30928039550778), Point(-105.78327941894531, 343.14288330078125, 190.0))), ConvexPolygon((Point(-105.78327941894531, 343.14288330078125, 190.0), Point(236.5274658203125, 184.2475128173828, 0.0), Point(239.52861022949182, 194.9963989257814, 1.807429067882295e-13), Point(-102.7821465290583, 353.891783623882, 190.0000076103702))), ConvexPolygon((Point(236.5274658203125, 184.2475128173828, 0.0), Point(-112.74012756347656, 346.37213134765625, 183.30928039550778), Point(-109.73899495224315, 357.12103180010325, 183.30928773788403), Point(239.52861022949182, 194.9963989257814, 1.807429067882295e-13)))]#[ConvexPolygon((Point(236.0, 184.0, 0.0), Point(-104.99999999999999, 343.0, 190.0), Point(-112.0, 345.99999999999994, 183.0))), ConvexPolygon((Point(239.0, 194.0, 0.0), Point(-109.0, 355.99999999999994, 183.0), Point(-101.99999999999999, 353.0, 190.0))), ConvexPolygon((Point(-104.99999999999999, 343.0, 190.0), Point(-101.99999999999999, 353.0, 190.0), Point(-109.0, 355.99999999999994, 183.0), Point(-112.0, 345.99999999999994, 183.0))), ConvexPolygon((Point(-104.99999999999999, 343.0, 190.0), Point(236.0, 184.0, 0.0), Point(239.0, 194.0, 0.0), Point(-101.99999999999999, 353.0, 190.0))), ConvexPolygon((Point(236.0, 184.0, 0.0), Point(-112.0, 345.99999999999994, 183.0), Point(-109.0, 355.99999999999994, 183.0), Point(239.0, 194.0, 0.0)))]

The project report "TypeError: Bug detected! please contact the author", can you help me solve this problem? Thank you!

Bug in ConvexPolygon-Plane intersection

There is currently a bug in the code for ConvexPolygon-Plane Intersection.
This bug is caused by a minor typo, and can be fixed relatively easily.

If you look at line 98-101 in "Geometry3D/calc/intersection.py", you'll find this code:

    elif isinstance(a, Plane) and isinstance(b, ConvexPolygon):
        return inter_plane_convexpolygon(a,b)
    elif isinstance(a, ConvexPolygon) and isinstance(a, Plane):
        return inter_plane_convexpolygon(b,a)

In the second elif statement, you can see that we are checking the type of a twice, without checking the type of b.

This should be changed to the following:

    elif isinstance(a, Plane) and isinstance(b, ConvexPolygon):
        return inter_plane_convexpolygon(a,b)
    elif isinstance(a, ConvexPolygon) and isinstance(b, Plane):
        return inter_plane_convexpolygon(b,a)

Until then, the work-around is to simply always specify the Plane first, and the ConvexPolygon second, so that you trigger the first elif, rather than the second.

Thanks in advance!

Question about point on a plane

Hello, thank you for your amazing project! Recently I'm trying to use this project to generate an intersection between two polyhedrons, but I found an error:
"ValueError: Convex Check Fails Because Point(-39.35859231445235, 261.35056323400175, 129.2997523368219) Is Not On Plane(Point(-27.878684988415753, 258.162898458097, 127.72269713190062), Vector(0.2489692168272217, 0.48178113934707206, 0.8401793039833086))"
After look through your source code, I think this error is caused by the precision of the cross between two vectors, for example, if we have three points:
a = Point(-39.47570506286104, 247.07101597009853, 122.23513421678561)
b = Point(-34.157972900849515, 245.67527429293494, 121.54460938703097)
c = Point(-30.09033189524111, 244.60764322271578, 121.01641296281727)
if we generate a plane based on this three points, in the code (/geometry/plane) we'll do:
vab = b.pv() - a.pv()
vac = c.pv() - a.pv()
vec1 = vab.cross(vac)
plane = Plane(a, vec1)
after that, I found "a in plane" is true, but both "b in plane" and "c in plane" will return false because vec1 is not accurate enough, can you help me solve this problem? Thank you so much!

Issue with intersection

I'm having problems with evaluating the intersection of a line and a cylinder. I use the following code:

from Geometry3D import *
def intersection_v2(xp,yp,zp,px,py,pz,xt,yt,zt,rt,ht):
    part = Line(Point(xp,yp,zp),Vector(px,py,pz))
    tank = Cylinder(Point(xt,yt,zt),191.6,302.4*x_unit_vector(),40)
    inters = intersection(part,tank)
    print(inters)

intersection_v2(100000000,100000000,100000000,-1,-1,-1,0,0,0,191.6,302.4)

I get that intersection is only a point (0,0,0) which is absurd. For smaller initial points (1000,1000,1000) the code behaves as intended. I tried to look for eventual limits on intersection but could not find them

ValueError: Check for the number of vertices, faces and edges fails, the polyhedron may not be closed

Hello, thank you for this amazing project, this is very helpful! right now I have two convex polyhedrons and I want to calculate their intersection, the two polyhedron are shown below:
a = [ConvexPolygon((Point(125.57989501953125, 33.03245544433594, 0.0), Point(-87.77513122558594, 348.1565246582031, 128.49752807617188), Point(-87.77513122558594, 348.1565246582031, 108.55316162109375))), ConvexPolygon((Point(134.3735809326172, 39.70722961425781, 0.0), Point(-78.9814453125, 354.831298828125, 108.55316162109374), Point(-78.9814453125, 354.831298828125, 128.4975280761719))), ConvexPolygon((Point(-87.77513122558594, 348.1565246582031, 128.49752807617188), Point(-78.9814453125, 354.831298828125, 128.4975280761719), Point(-78.9814453125, 354.831298828125, 108.55316162109374), Point(-87.77513122558594, 348.1565246582031, 108.55316162109375))), ConvexPolygon((Point(-87.77513122558594, 348.1565246582031, 128.49752807617188), Point(125.57989501953125, 33.03245544433594, 0.0), Point(134.3735809326172, 39.70722961425781, 0.0), Point(-78.9814453125, 354.831298828125, 128.4975280761719))), ConvexPolygon((Point(125.57989501953125, 33.03245544433594, 0.0), Point(-87.77513122558594, 348.1565246582031, 108.55316162109375), Point(-78.9814453125, 354.831298828125, 108.55316162109374), Point(134.3735809326172, 39.70722961425781, 0.0)))]#[ConvexPolygon((Point(-106.67681884765625, 302.38067626953125, 190.0), Point(-125.07760620117188, 319.8424072265625, 184.20480346679688), Point(154.2360382080078, 54.783660888671875, -0.0))), ConvexPolygon((Point(166.9486541748047, 64.43305969238281, -0.0), Point(-112.36498908762633, 329.491819597817, 184.20480836937483), Point(-93.96420124437704, 312.03008817604496, 190.00000505681606))), ConvexPolygon((Point(-125.07760620117188, 319.8424072265625, 184.20480346679688), Point(-106.67681884765625, 302.38067626953125, 190.0), Point(-93.96420124437704, 312.03008817604496, 190.00000505681606), Point(-112.36498908762633, 329.491819597817, 184.20480836937483))), ConvexPolygon((Point(-106.67681884765625, 302.38067626953125, 190.0), Point(154.2360382080078, 54.783660888671875, -0.0), Point(166.9486541748047, 64.43305969238281, -0.0), Point(-93.96420124437704, 312.03008817604496, 190.00000505681606))), ConvexPolygon((Point(154.2360382080078, 54.783660888671875, -0.0), Point(-125.07760620117188, 319.8424072265625, 184.20480346679688), Point(-112.36498908762633, 329.491819597817, 184.20480836937483), Point(166.9486541748047, 64.43305969238281, -0.0)))]

b = [ConvexPolygon((Point(-47.52482604980469, 113.43841552734375, 128.61720275878906), Point(-47.52482604980469, 113.43841552734375, 106.79966735839844), Point(59.184303283691406, 493.0682373046875, -0.0))), ConvexPolygon((Point(-56.86540222167969, 119.09527587890625, 128.61720275878906), Point(49.843727111816406, 498.72509765625, -0.0), Point(-56.86540222167969, 119.09527587890625, 106.79966735839844))), ConvexPolygon((Point(-47.52482604980469, 113.43841552734375, 128.61720275878906), Point(-56.86540222167969, 119.09527587890625, 128.61720275878906), Point(-56.86540222167969, 119.09527587890625, 106.79966735839844), Point(-47.52482604980469, 113.43841552734375, 106.79966735839844))), ConvexPolygon((Point(-47.52482604980469, 113.43841552734375, 128.61720275878906), Point(59.184303283691406, 493.0682373046875, -0.0), Point(49.843727111816406, 498.72509765625, -0.0), Point(-56.86540222167969, 119.09527587890625, 128.61720275878906))), ConvexPolygon((Point(59.184303283691406, 493.0682373046875, -0.0), Point(-47.52482604980469, 113.43841552734375, 106.79966735839844), Point(-56.86540222167969, 119.09527587890625, 106.79966735839844), Point(49.843727111816406, 498.72509765625, -0.0)))]#[ConvexPolygon((Point(228.86135864257812, 328.18670654296875, 0.0), Point(-94.588623046875, 219.96185302734375, 190.0), Point(-117.3912353515625, 212.33221435546875, 190.0))), ConvexPolygon((Point(224.04629516601562, 340.3481750488281, 0.0), Point(-122.20629882812509, 224.4936828613281, 190.00000000000003), Point(-99.40368652343749, 232.12332153320312, 190.00000000000003))), ConvexPolygon((Point(-94.588623046875, 219.96185302734375, 190.0), Point(-99.40368652343749, 232.12332153320312, 190.00000000000003), Point(-122.20629882812509, 224.4936828613281, 190.00000000000003), Point(-117.3912353515625, 212.33221435546875, 190.0))), ConvexPolygon((Point(228.86135864257812, 328.18670654296875, 0.0), Point(224.04629516601562, 340.3481750488281, 0.0), Point(-99.40368652343749, 232.12332153320312, 190.00000000000003), Point(-94.588623046875, 219.96185302734375, 190.0))), ConvexPolygon((Point(-117.3912353515625, 212.33221435546875, 190.0), Point(-122.20629882812509, 224.4936828613281, 190.00000000000003), Point(224.04629516601562, 340.3481750488281, 0.0), Point(228.86135864257812, 328.18670654296875, 0.0)))]
when I build this two polyhderon and run intersection:
intersection(a, b)
the code always gives me “ValueError: Check for the number of vertices, faces and edges fail, the polyhedron may not be closed”,I'm pretty sure these two polyhedrons have a 3-D intersection, so I think it is caused by the numerical accuracy; can anyone help me solve this problem? Thank you so much!!

Intersection Issue

Hi,

Really enjoy this library but I have a small problem and I can't figure out why it isn't working.
I want to calculate the intersection between two planes, but some calculations return a None even if the planes doe have an intersection?
Does someone have any ideas?

This is my code:

`from Geometry3D import *

plane1 = ConvexPolygon((Point(61.32, 0.0, 0.58), Point(-0.21, 50.58, -28.91), Point(-0.21, 0.0, -28.91)))
plane2 = ConvexPolygon((Point(-50.21, 20.0, -78.91), Point(-50.21, 20.0, 50.58), Point(111.32, 20.0, 50.58), Point(111.32, 20.0, -78.91)))

inter = intersection(plane1,plane2)
print(inter)

r = Renderer()
r.add((plane1,'r',2))
r.add((plane2,'b',2),normal_length = 0)
r.show()`

Error when getting the intersection of 2 Convex Polyhedrons

Hi there, I am using your library to check whether 2 convex polyhedrons intersect each other. The library has worked for many of these polyhedrons before, but I'm now getting a value error when checking some intersections. Here is the stack trace:


File python3.11/site-packages/Geometry3D/geometry/body.py:14, in GeoBody.intersection(self, other)
     12 """return the intersection between self and other"""
     13 from ..calc.intersection import intersection
---> 14 return intersection(self, other)

File python3.11/site-packages/Geometry3D/calc/intersection.py:138, in intersection(a, b)
    136 # convex polyhedron
    137 elif isinstance(a,ConvexPolyhedron) and isinstance(b,ConvexPolyhedron):
--> 138     return inter_convexpolyhedron_convexpolyhedron(a,b)
    139 elif isinstance(a, ConvexPolyhedron) and isinstance(b, HalfLine):
    140     return inter_convexpolyhedron_halfline(a,b)

File python3.11/site-packages/Geometry3D/calc/intersection.py:807, in inter_convexpolyhedron_convexpolyhedron(cph1, cph2)
    805         cpg_set.add(inter)
    806 for cpg in cph2.convex_polygons:
--> 807     inter = inter_convexpolygon_convexPolyhedron(cph1,cpg)
    808     if inter is None:
    809         continue

File python3.11/site-packages/Geometry3D/calc/intersection.py:746, in inter_convexpolygon_convexPolyhedron(cph, cpg)
    737 def inter_convexpolygon_convexPolyhedron(cph,cpg):
    738     """Input:
    739     cph: a ConvexPolyhedron
    740     cpg: a ConvexPolygon
   (...)
    744     the intersection part of cph and cpg
    745     """
--> 746     inter_p_cph = intersection(cph,cpg.plane)
    747     if inter_p_cph is None:
    748         return None

File python3.11/site-packages/Geometry3D/calc/intersection.py:105, in intersection(a, b)
    103     return inter_plane_convexpolyhedron(a,b)
    104 elif isinstance(a,ConvexPolyhedron) and isinstance(b, Plane):
--> 105     return inter_plane_convexpolyhedron(b,a)
    106 elif isinstance(a, Plane) and isinstance(b, HalfLine):
    107     return inter_plane_halfline(a,b)

File python3.11/site-packages/Geometry3D/calc/intersection.py:508, in inter_plane_convexpolyhedron(a, b)
    506     return Segment(point_tuple[0],point_tuple[1])
    507 else:
--> 508     return ConvexPolygon(point_tuple)

File python3.11/site-packages/Geometry3D/geometry/polygon.py:133, in ConvexPolygon.__init__(self, pts, reverse, check_convex)
    129     self.plane = Plane(self.points[0],self.points[1],self.points[2])
    131 self.center_point = self._get_center_point()
--> 133 self._check_and_sort_points()

File python3.11/site-packages/Geometry3D/geometry/polygon.py:211, in ConvexPolygon._check_and_sort_points(self)
    209 for point in self.points:
    210     if not point in self.plane:
--> 211         raise ValueError('Convex Check Fails Because {} Is Not On {}'.format(point,self.plane))
    212     pv = point.pv() - self.center_point.pv()
    213     y_coordinate = pv * v0

ValueError: Convex Check Fails Because Point(-636.2316726828756, -323.39055174300415, -4.031296527409776) Is Not On Plane(Point(-636.2978665768319, -318.69779661131014, -3.9293749129306144), Vector(0.9996419880957945, 0.01360005268929717, 0.02304200952034214))

This is with:
bbox1 = ConvexPolyhedron({Point(-638.0112640092382, -339.2830706018351, -4.539983707967987), Point(-636.0698922945523, -334.745069045331, -4.34812808219203), Point(-638.0759883109075, -334.772361827949, -4.394369120540701), Point(-636.03961227503, -339.30545799626975, -2.970108037052072), Point(-638.0457082913852, -339.33275077888777, -3.0163490754007425), Point(-638.1104325930545, -334.82204200500166, -2.870734487973457), Point(-636.005167992883, -339.2557778192171, -4.493742669619316), Point(-636.1043365766993, -334.79474922238364, -2.824493449624786)})

bbox2 = ConvexPolyhedron({Point(-638.2855200600773, -318.9122950789289, -3.982766365222638), Point(-637.8170533786531, -323.5896296800596, -2.6317697118413648), Point(-638.3208004655334, -318.94409328652847, -2.54160145408265), Point(-636.3307758549279, -318.72933893769624, -2.4881463096358347), Point(-635.7917483625915, -323.3430771236278, -4.019479478534537), Point(-636.2954954494718, -318.69754073009665, -3.9293112207758227), Point(-637.781772973197, -323.55783147246, -4.072934622981353), Point(-635.8270287680476, -323.3748753312274, -2.5783145673945493)})

I've gotten the same error with several different bounding box pairings. I'm not sure if you have any insight as to why this error is being triggered by these combinations? The ConvexPolyhedrons are being constructed in the same way (I'm building them with a point and 3 vectors), so it's odd that some are failing in this way.

An error in determining the intersection of triangles whose coordinates differ by 10 times

Hello, dear developers of the Geometry3D library!
While using the intersection() function, an error was detected for a pair of triangles, which is probably related to incorrect rounding or overflow. The coordinates of the points in one set differ from the other by increasing each number by a factor of 10.
The file with the minimum reproducible code example is attached below. It follows from the first set of numbers that the triangles do not intersect, and from the second set it follows that they intersect.
Sincerely, Andrey Kazachkov.

import Geometry3D as geometry

def creating_points(numbers, n_triangles):

    n_numbers = n_triangles*9
    points = []

    for i in range(0, n_numbers, 3):
        points.append(geometry.Point(numbers[i], numbers[i+1], numbers[i+2]))

    return points

def creating_triangles(points, n_triangles):

    triangles = []
    n_points = n_triangles*3

    for i in range(0, n_points, 3):
        triangles.append(geometry.ConvexPolygon((points[i], points[i+1], points[i+2])))

    return triangles

def intersecting_triangles(triangles):

    intersecting_indexes = []
    n_intersections = 0

    for i in range(len(triangles) - 1):
        for j in range(i + 1, len(triangles)):    
            if geometry.intersection(triangles[i], triangles[j]):
                if i not in intersecting_indexes:
                    intersecting_indexes.append(i)
                if j not in intersecting_indexes:
                    intersecting_indexes.append(j)
                n_intersections = n_intersections + 1
    return intersecting_indexes, n_intersections

def main():

    n_intersections = 0
    n_triangles = 2

    if 0:
        numbers = [29.3505, 805.295, 397.635, -248.565, -404.623, -873.618, -386.796, -76.4378, -878.078,
                    -120.028, -992.064, 12.6612, -729.661, -244.151, -979.961, 997.444, 982.96, -259.114]
    else:
        numbers = [2.93505, 80.5295, 39.7635, -24.8565, -40.4623, -87.3618, -38.6796, -7.64378, -87.8078,
                    -12.0028, -99.2064, 1.26612, -72.9661, -24.4151, -97.9961, 99.7444, 98.296,-25.9114]

    points = creating_points(numbers, n_triangles)
    triangles = creating_triangles(points, n_triangles)
    intersecting_indexes, n_intersections = intersecting_triangles(triangles)

    print(f"n_intersections = {n_intersections}")
        
main()

Export geometries to file

It will be great to have a direct method for exporting geometries to 3D supported files (i.e .obj/.off/.mesh file types).

intersection of two convexpolygon

Hello, for the below two convex polygon there should have a intersect convex polygon, but the result is None,

c = ConvexPolygon((Point(25.917035916717097, 249.4823416602293, 140.95893683162333), Point(15.86926746447375, 234.15206098547773, 144.81489658305364), Point(16.802552489221853, 234.50594363623017, 127.52971818115088), Point(26.825470531894382, 249.82680154239767, 124.13400771198833)))
p = Plane(Point(152.0, 436.0, 0.0), Vector(-0.8398036066330478, 0.541808778472934, -0.03425127524329979))
print(c in p)
c1 = ConvexPolygon((Point(152.0, 436.0, 0.0), Point(-28.060504913330078, 168.9019012451172, 189.7555389404297), Point(-8.086238861083984, 199.8620147705078, 189.7555389404297)))
print(c1 in p)
print(intersection(c,c1))
r = Renderer()
r.add((c,'r',1),normal_length = 0)
r.add((c1,'g',1),normal_length = 0)
r.show()

thank you for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.