GPv3: Compute the "curve plane normal" using a principal component analysis #117275

Open
opened 2024-01-18 12:34:47 +01:00 by Falk David · 1 comment
Member

It's often usefull to know if a grease pencil stroke lies on a plane and what the normal vector of that plane is.

Currently there is drawing.curve_plane_normals(). This tries computing such a normal using the newell method.
There are issues with this:

  • The newell method will output a vector with a length that is proportional to the signed area of the curve. E.g. if the curve forms a perfect figure-8, the vector would be 0 and the method fails.
  • The direction of the vector depends on the winding number. E.g. if the stroke is drawn in a clockwise order the vector will be different to when it is drawn anti-clockwise.
  • When the stroke is not in a plane, this vector becomes somewhat arbitrary.

A better method would use a PCA (https://en.wikipedia.org/wiki/Principal_component_analysis)

  • Get the centroid of points
  • Build a covariance matrix (sum of dot products of deltas from the centroid)
  • Use BLI_svd_m3 to do a singular value decomposition
  • The result is a rotation matrix and the variance along the 3 principal axes. plane normal would be the 3rd axis (smallest variance)

This not only will result in a better normal vector, it will also compute "how much the stroke is not on the plane".
Having this value can be useful to e.g. do a different computation for strokes that are "3D" vs "2D".

It's often usefull to know if a grease pencil stroke lies on a plane and what the normal vector of that plane is. Currently there is `drawing.curve_plane_normals()`. This tries computing such a normal using the newell method. There are issues with this: * The newell method will output a vector with a length that is proportional to the signed area of the curve. E.g. if the curve forms a perfect figure-8, the vector would be 0 and the method fails. * The direction of the vector depends on the winding number. E.g. if the stroke is drawn in a clockwise order the vector will be different to when it is drawn anti-clockwise. * When the stroke is not in a plane, this vector becomes somewhat arbitrary. A better method would use a PCA (https://en.wikipedia.org/wiki/Principal_component_analysis) * Get the centroid of points * Build a covariance matrix (sum of dot products of deltas from the centroid) * Use `BLI_svd_m3` to do a singular value decomposition * The result is a rotation matrix and the variance along the 3 principal axes. plane normal would be the 3rd axis (smallest variance) This not only will result in a better normal vector, it will also compute "how much the stroke is not on the plane". Having this value can be useful to e.g. do a different computation for strokes that are "3D" vs "2D".
Falk David added the
Type
To Do
label 2024-01-18 12:34:47 +01:00
Falk David added this to the Grease Pencil project 2024-01-18 12:34:49 +01:00
Falk David changed title from GPv3: Compute the "curve plane normal" to GPv3: Compute the "curve plane normal" using a principal component analysis 2024-01-18 12:35:17 +01:00
Member

Implementation of the method in geometry nodes, as proof-of-concept: #117322
Screenshot_20240119_110017

Attached file uses the node to find principal components of randomized point cloud positions for testing purposes.
image

Implementation of the method in geometry nodes, as proof-of-concept: #117322 ![Screenshot_20240119_110017](/attachments/0bf0084e-b6a6-4393-941d-94e95e329aad) Attached file uses the node to find principal components of randomized point cloud positions for testing purposes. ![image](/attachments/1c340783-79f1-45e8-a4bb-78b04875546d)
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
2 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#117275
No description provided.