mathutils.geometry.intersect_line_line does not behave consistently for 2D vectors on Linux #101591

Closed
opened 2022-10-04 13:46:08 +02:00 by Dion Moult · 6 comments

Apologies if I missed something in the documentation, but from what I read I assumed intersect_line_line to take two lines defined by 4 points and find their intersection. Therefore I would expect any 2D lines that aren't parallel to always have a point of intersection.

However the behaviour seems to depend on a few factors - is this documented anywhere, and is this intended?

import bpy
from bpy import data as D
from bpy import context as C
from mathutils import *
from math import *

a = [Vector((0,0)), Vector((0,1))]
b = [Vector((0.8,1)), Vector((0,1))]

# Returns nan vector
print(geometry.intersect_line_line(a[0], a[1], b[0], b[1]))

# Returns correct first vector
print(geometry.intersect_line_line(a[1], a[0], b[0], b[1]))

# Returns correct both vectors
print(geometry.intersect_line_line(a[1], a[0], b[1], b[0]))

# Returns 0,1 as expected
print(geometry.intersect_line_line(a[0].to_3d(), a[1].to_3d(), b[0].to_3d(), b[1].to_3d()))

I am able to recreate it but only on Linux. I've tested the latest 3.3 stable downloaded from Blender.org. It seems sporadic - if I restart Blender, run the same code (in the text editor) sometimes it will work, sometimes I will get nans or different results in the 2D vectors vs the 3D vectors.

Here are a few examples of what might be printed:

(Vector((0.0, 1.0)), Vector((0.0, 1.0)))
(Vector((0.0, 1.0)), Vector((0.0, 1.0)))
(Vector((0.0, 1.0)), Vector((0.800000011920929, 1.0)))
(Vector((0.0, 1.0, 0.0)), Vector((0.0, 1.0, 0.0)))
# ... restart blender and try again ...
(Vector((0.0, 1.0)), Vector((0.0, 1.0)))
(Vector((0.0, 1.0)), Vector((0.0, 1.0)))
(Vector((0.0, 1.0)), Vector((1.7022413225232148e-40, 1.0)))
(Vector((0.0, 1.0, 0.0)), Vector((0.0, 1.0, 0.0)))
# ... restart blender and try again ...
(Vector((nan, nan)), Vector((nan, nan)))
(Vector((0.0, 1.0)), Vector((nan, nan)))
(Vector((0.0, 1.0)), Vector((0.0, 1.0)))
(Vector((0.0, 1.0, 0.0)), Vector((0.0, 1.0, 0.0)))

Here's another snippet that has odd results:

import bpy
from bpy import data as D
from bpy import context as C
from mathutils import *
from math import *
 
a = [Vector((-0.08, -0.88)), Vector((3.47, -1.6))]
b = [Vector((0, -1.6)), Vector((0, -0.6))]
 
- Shouldn't these two results be the same?
- print((a[0], a[1], b[0], b[1]))
print(geometry.intersect_line_line(a[0], a[1], b[0], b[1]))
- When using 3D vectors, I get the expected result (i.e. returns 2 same coords, where X ordinate = 0)
- print((a[0].to_3d(), a[1].to_3d(), b[0].to_3d(), b[1].to_3d()))
print(geometry.intersect_line_line(a[0].to_3d(), a[1].to_3d(), b[0].to_3d(), b[1].to_3d()))

I've tested it on my Linux (Gentoo 64bit) machine and am able to recreate weird results now and then. Another user helped test on another Linux machine (Ubuntu 22.04 64bit - also downloaded binary from Blender.org website) and was able to get nan vectors about 10% of the time. A Windows user was not able to reproduce. I was also not able to reproduce on another Windows machine.

I've noticed that when using 3D vectors, the results tend to always be correct, whereas the weird result only occurs with 2D vectors.

image.png

Apologies if I missed something in the documentation, but from what I read I assumed intersect_line_line to take two lines defined by 4 points and find their intersection. Therefore I would expect any 2D lines that aren't parallel to always have a point of intersection. However the behaviour seems to depend on a few factors - is this documented anywhere, and is this intended? ``` import bpy from bpy import data as D from bpy import context as C from mathutils import * from math import * a = [Vector((0,0)), Vector((0,1))] b = [Vector((0.8,1)), Vector((0,1))] # Returns nan vector print(geometry.intersect_line_line(a[0], a[1], b[0], b[1])) # Returns correct first vector print(geometry.intersect_line_line(a[1], a[0], b[0], b[1])) # Returns correct both vectors print(geometry.intersect_line_line(a[1], a[0], b[1], b[0])) # Returns 0,1 as expected print(geometry.intersect_line_line(a[0].to_3d(), a[1].to_3d(), b[0].to_3d(), b[1].to_3d())) ``` I am able to recreate it but _only_ on Linux. I've tested the latest 3.3 stable downloaded from Blender.org. It seems sporadic - if I restart Blender, run the same code (in the text editor) sometimes it will work, sometimes I will get nans or different results in the 2D vectors vs the 3D vectors. Here are a few examples of what might be printed: ``` (Vector((0.0, 1.0)), Vector((0.0, 1.0))) (Vector((0.0, 1.0)), Vector((0.0, 1.0))) (Vector((0.0, 1.0)), Vector((0.800000011920929, 1.0))) (Vector((0.0, 1.0, 0.0)), Vector((0.0, 1.0, 0.0))) # ... restart blender and try again ... (Vector((0.0, 1.0)), Vector((0.0, 1.0))) (Vector((0.0, 1.0)), Vector((0.0, 1.0))) (Vector((0.0, 1.0)), Vector((1.7022413225232148e-40, 1.0))) (Vector((0.0, 1.0, 0.0)), Vector((0.0, 1.0, 0.0))) # ... restart blender and try again ... (Vector((nan, nan)), Vector((nan, nan))) (Vector((0.0, 1.0)), Vector((nan, nan))) (Vector((0.0, 1.0)), Vector((0.0, 1.0))) (Vector((0.0, 1.0, 0.0)), Vector((0.0, 1.0, 0.0))) ``` Here's another snippet that has odd results: ``` import bpy from bpy import data as D from bpy import context as C from mathutils import * from math import * a = [Vector((-0.08, -0.88)), Vector((3.47, -1.6))] b = [Vector((0, -1.6)), Vector((0, -0.6))] - Shouldn't these two results be the same? - print((a[0], a[1], b[0], b[1])) print(geometry.intersect_line_line(a[0], a[1], b[0], b[1])) - When using 3D vectors, I get the expected result (i.e. returns 2 same coords, where X ordinate = 0) - print((a[0].to_3d(), a[1].to_3d(), b[0].to_3d(), b[1].to_3d())) print(geometry.intersect_line_line(a[0].to_3d(), a[1].to_3d(), b[0].to_3d(), b[1].to_3d())) ``` I've tested it on my Linux (Gentoo 64bit) machine and am able to recreate weird results now and then. Another user helped test on another Linux machine (Ubuntu 22.04 64bit - also downloaded binary from Blender.org website) and was able to get nan vectors about 10% of the time. A Windows user was not able to reproduce. I was also not able to reproduce on another Windows machine. I've noticed that when using 3D vectors, the results tend to always be correct, whereas the weird result only occurs with 2D vectors. ![image.png](https://archive.blender.org/developer/F13613644/image.png)
Author

Added subscriber: @Moult

Added subscriber: @Moult

Added subscriber: @Carlos-Villagrasa

Added subscriber: @Carlos-Villagrasa

This issue was referenced by 283af78657

This issue was referenced by 283af786579b4d5e094332a15d95a5c888647b13

This issue was referenced by e2beed6ae2

This issue was referenced by e2beed6ae2223cb56f64cc6e01bd284ae53fd968

This issue was referenced by 0484b6bb18

This issue was referenced by 0484b6bb181635b1310275c1d176cbf076d98ce5

Changed status from 'Needs Triage' to: 'Resolved'

Changed status from 'Needs Triage' to: 'Resolved'
Campbell Barton self-assigned this 2022-10-06 08:34:40 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#101591
No description provided.