geometry

package
v0.2.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollinearPoints        OrientationPoints = -1
	ClockwisePoints                          = 0
	CounterClockwisePoints                   = 1
)
View Source
const (
	// Boundary edge
	Boundary = -1

	// Removed element
	Removed = -2

	// Undefined state only for not valid algorithm
	Undefined = -3
	Fixed     = 100
	Movable   = 200
)
View Source
const Eps3D = 1e-5

Eps3D is default epsilon for 3D operations

Variables

View Source
var (
	// ErrorDivZero is typical result with not acceptable solving
	ErrorDivZero = fmt.Errorf("div value is too small")

	// ErrorNotValidSystem is typical return only if system of
	// linear equation have not valid data
	ErrorNotValidSystem = fmt.Errorf("not valid system")
)
View Source
var (
	// Eps is epsilon - precision of intersection
	Eps = 1e-10
)

Functions

func AngleBetween

func AngleBetween(center, from, mid, to, a Point) (res bool)

AngleBetween return true for angle case from <= a <= to

func Arc

func Arc(Arc0 Point, Arc1 Point, Arc2 Point) (xc float64, yc float64, r float64)

Arc return parameters of circle

func ArcSplitByPoint

func ArcSplitByPoint(Arc0 Point, Arc1 Point, Arc2 Point, pi ...Point) (res [][3]Point, err error)

ArcSplitByPoint return points of arcs with middle point if pi is empty or slice of arcs.

DO NOT CHECKED POINT ON ARC

func Area

func Area(tr0 Point, tr1 Point, tr2 Point) float64

Area return area of triangle

func Check

func Check(pps ...Point) error

Check - check input data

func Distance

func Distance(p0 Point, p1 Point) float64

Distance between two points

func Distance128

func Distance128(p0, p1 Point) float64

Distance128 is distance between 2 points with 128-bit precisions

func Distance3d

func Distance3d(p0 Point3d, p1 Point3d) float64

Distance3d is distance between 2 points in 3D

func Line

func Line(p0 Point, p1 Point) (A float64, B float64, C float64)

Line parameters by formula: Ax+By+C = 0

func LineArc

func LineArc(Line0 Point, Line1 Point, Arc0 Point, Arc1 Point, Arc2 Point) (pi []Point, stA State, stB State)

LineArc return state and intersections points between line and arc

func LineLine

func LineLine(pa0 Point, pa1 Point, pb0 Point, pb1 Point) (pi []Point, stA State, stB State)

LineLine return analysis of two segments

Design of segments:

                                            //
<-- rb00 -- pb0*==========*pb1 -- rb11 -->  // Segment B
                                            //
<-- ra00 -- pa0*==========*pa1 -- ra11 -->  // Segment A
{   ray   }{      segment     }{   ray   }  //
                                            //

Input data:

ipa0, ipa1 - point indexes of segment A
ipb0, ipb1 - point indexes of segment B
pps      - pointer of point slice

Output data:

pi - intersection point
st - states of analysis

Reference:

[1]  https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection

func LineLine3d

func LineLine3d(a0 Point3d, a1 Point3d, b0 Point3d, b1 Point3d) (ratioA float64, ratioB float64, intersect bool)

LineLine3d return intersection of two points. Point on line corner ignored

func Linear

func Linear(a11 float64, a12 float64, b1 float64, a21 float64, a22 float64, b2 float64) (x float64, y float64, err error)

Linear equations solving:

a11*x + a12*y = b1
a21*x + a22*y = b2

func MirrorLine

func MirrorLine(sp0, sp1 Point, mp0, mp1 Point) (ml0 Point, ml1 Point, err error)

MirrorLine return intersection point and second mirrored point from mirror line (mp0-mp1) and ray (sp0-sp1)

func Plane

func Plane(p1 Point3d, p2 Point3d, p3 Point3d) (A float64, B float64, C float64, D float64)

Plane equation `A*x+B*y+C*z+D=0`

func PointArc

func PointArc(pt Point, Arc0 Point, Arc1 Point, Arc2 Point) (pi []Point, stA, stB State)

PointArc return state and intersections points between point and arc

func PointInCircle

func PointInCircle(point Point, circle [3]Point) bool

PointInCircle return true only if point inside circle based on 3 circles points

func PointLine

func PointLine(pt Point, pb0 Point, pb1 Point) (pi []Point, stA State, stB State)

PointLine return states between point and line.

func PointLine3d

func PointLine3d(p Point3d, l0, l1 Point3d) (intersect bool)

PointLine3d return true only if point located on line segment

func PointLineDistance

func PointLineDistance(pc Point, p0 Point, p1 Point) (distance float64)

PointLineDistance return distance between line and point.

Equation of line:

(y2-y1)*(x-x1) = (x2-x1)(y-y1)
dy*(x-x1) = dx*(y-y1)
dy*x-dy*x1-dx*y+dx*y1 = 0
Ax+By+C = 0
A = dy
B = -dx
C = -dy*x1+dx*y1

Distance from point (xm, ym) to line:

d = |(A*xm+B*ym+C)/sqrt(A^2+B^2)|

func PointOnPlane3d

func PointOnPlane3d(A float64, B float64, C float64, D float64, p Point3d) (on bool)

func PointPoint

func PointPoint(pt0 Point, pt1 Point) (pi []Point, stA State, stB State)

PointPoint return states between two points.

func PointPoint3d

func PointPoint3d(p0 Point3d, p1 Point3d) (intersect bool)

PointPoint3d return true only if points have same coordinate

func PointTriangle3d

func PointTriangle3d(p Point3d, t0 Point3d, t1 Point3d, t2 Point3d) (intersect bool)

PointTriangle3d return true only if point located inside triangle but do not check point on triangle edge

func PowE2

func PowE2(x float64) float64

E2 function replace `math.Pow(x,2.0)`

func PowE3

func PowE3(x float64) float64

E3 function replace `math.Pow(x,3.0)`

func PowE4

func PowE4(x float64) float64

E4 function replace `math.Pow(x,4.0)`

func PowEn

func PowEn(x float64, e int) float64

En function replace `math.Pow(x,e)`

func SamePoints

func SamePoints(p0 Point, p1 Point) bool

SamePoints return true only if point on very distance or with same coordinates

func SamePoints3d

func SamePoints3d(p0 Point3d, p1 Point3d) bool

SamePoints3d return true only if point on very distance or with same coordinates

func TriangleSplitByPoint

func TriangleSplitByPoint(pt Point, tr0 Point, tr1 Point, tr2 Point) (res [][3]Point, lineIntersect int, err error)

TriangleSplitByPoint split triangle on triangles only if point inside triangle or on triangle edge

func ZeroLine3d

func ZeroLine3d(l0 Point3d, l1 Point3d) (zero bool)

ZeroLine3d return true only if lenght of line segment is zero

func ZeroTriangle3d

func ZeroTriangle3d(t0 Point3d, t1 Point3d, t2 Point3d) (zero bool)

ZeroTriangle3d return true only if triangle have zero area

Types

type Mesh

type Mesh struct {
	Points    []int    // tags for points
	Triangles [][3]int // indexes of near triangles
	Debug     bool
	Log       bool
	// contains filtered or unexported fields
}

Mesh is based structure of triangulation. Triangle is data structure "Nodes, ribs и triangles" created by book "Algorithm building and analyse triangulation", A.B.Skvorcov

Scketch:
+------------------------------------+
|              tr[0]                 |
|  nodes[0]    ribs[0]      nodes[1] |
| o------------------------o         |
|  \                      /          |
|   \                    /           |
|    \                  /            |
|     \                /             |
|      \              /              |
|       \            /  ribs[1]      |
|        \          /   tr[1]        |
|  ribs[2]\        /                 |
|  tr[2]   \      /                  |
|           \    /                   |
|            \  /                    |
|             \/                     |
|              o  nodes[2]           |
+------------------------------------+

func NewMesh

func NewMesh() *Mesh

New triangulation created by model

func (*Mesh) AddLine

func (mesh *Mesh) AddLine(inp1, inp2 Point) (err error)

AddLine is add line in triangulation with tag

func (*Mesh) AddPoint

func (mesh *Mesh) AddPoint(p Point, tag int) (idp int, err error)

AddPoint is add points with tag

func (*Mesh) Check

func (mesh *Mesh) Check() (err error)

Check triangulation on point, line, triangle rules

func (*Mesh) Clockwise

func (mesh *Mesh) Clockwise()

Clockwise change all triangles to clockwise orientation

func (*Mesh) Compile

func (mesh *Mesh) Compile(model *Model) (err error)

func (*Mesh) Delanay

func (mesh *Mesh) Delanay(tri ...int) (err error)

TODO delanay only for some triangles, if list empty then for all triangles

func (*Mesh) GetMaterials

func (mesh *Mesh) GetMaterials(ps ...Point) (materials []int, err error)

GetMaterials return materials for each point

func (*Mesh) Materials

func (mesh *Mesh) Materials() (err error)

Materials identify all triangles splitted by lines, only if points slice is empty. If points slice is not empty, then return material mark number for each point

func (*Mesh) Model

func (mesh *Mesh) Model() *Model

func (*Mesh) Smooth

func (mesh *Mesh) Smooth(pts ...int) (err error)

Smooth move all movable point by average distance

func (*Mesh) Split

func (mesh *Mesh) Split(d float64) (err error)

Split all triangles edge on distance `d`

type Model

type Model struct {
	Points    []Point  // Points is slice of points
	Lines     [][3]int // Lines store 2 index of Points and last for tag
	Arcs      [][4]int // Arcs store 3 index of Points and last for tag
	Triangles [][4]int // Triangles store 3 index of Points and last for tag/material
}

Model of points, lines, arcs for prepare of triangulation

func NewModel

func NewModel() *Model

func (*Model) AddArc

func (m *Model) AddArc(start, middle, end Point, tag int)

AddArc add arc into model with specific tag

func (*Model) AddCircle

func (m *Model) AddCircle(xc, yc, r float64, tag int)

AddCircle add arcs based on circle geometry into model with specific tag

func (*Model) AddLine

func (m *Model) AddLine(start Point, end Point, tag int)

AddLine add line into model with specific tag

func (*Model) AddModel

func (m *Model) AddModel(from Model)

AddModel inject model into model

func (*Model) AddMultiline

func (m *Model) AddMultiline(tag int, ps ...Point)

AddMultiline add many lines with specific tag

func (*Model) AddPoint

func (m *Model) AddPoint(p Point) (index int)

AddPoint return index in model slice point

func (*Model) AddTriangle

func (m *Model) AddTriangle(start, middle, end Point, tag int)

AddTriangle add triangle into model with specific tag/material

func (*Model) ArcsToLines

func (m *Model) ArcsToLines()

ArcsToLines convert arc to lines

func (*Model) ConvexHullTriangles

func (m *Model) ConvexHullTriangles()

ConvexHullTriangles add triangles of model convex hull

func (*Model) Copy

func (m *Model) Copy() (dst Model)

Copy return copy of Model

func (*Model) Dxf

func (m *Model) Dxf() string

Dxf return string in dxf drawing format https://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf

func (*Model) Intersection

func (m *Model) Intersection()

Intersection change model with finding all model intersections

func (*Model) JSON

func (m *Model) JSON() (_ string, err error)

JSON convert model in JSON format

func (*Model) Merge

func (m *Model) Merge(from Model)

func (*Model) MinPointDistance

func (m *Model) MinPointDistance() (distance float64)

MinPointDistance return minimal between 2 points

func (*Model) Move

func (m *Model) Move(dx, dy float64)

Move all points of model

func (*Model) Read

func (m *Model) Read(filename string) (err error)

Read model from file with filename in JSON format

func (*Model) RemoveEmptyPoints

func (m *Model) RemoveEmptyPoints()

RemoveEmptyPoints removed point not connected to line, arcs, triangles

func (*Model) RemovePoint

func (m *Model) RemovePoint(remove func(p Point) bool)

RemovePoint removed point in accoding to function `filter`

func (*Model) Rotate

func (m *Model) Rotate(xc, yc, angle float64)

Rotate all points of model around point {xc,yc}

func (*Model) Split

func (m *Model) Split(d float64)

Split all model lines, arcs by distance `d`

func (*Model) String

func (m *Model) String() string

String return a standard model view

func (*Model) TagProperty

func (m *Model) TagProperty() (length []float64, area []float64)

TagProperty return length of lines, area of triangles for each tag. Arcs are ignored

func (*Model) Write

func (m *Model) Write(filename string) (err error)

Write model into file with filename in JSON format

type OrientationPoints

type OrientationPoints int8

OrientationPoints is orientation points state

func Orientation

func Orientation(p1 Point, p2 Point, p3 Point) OrientationPoints

func Orientation128

func Orientation128(p1 Point, p2 Point, p3 Point) OrientationPoints

type Point

type Point struct {
	X, Y float64
}

Point is store of point coordinates

func ConvexHull

func ConvexHull(points []Point) (chain []Point)

ConvexHull return chain of convex points

func MiddlePoint

func MiddlePoint(p0 Point, p1 Point) Point

MiddlePoint calculate middle point precisely.

func Rotate

func Rotate(xc, yc, angle float64, point Point) (p Point)

Rotate point about (xc,yc) on angle

func (Point) String

func (p Point) String() string

String is implementation of Stringer implementation for formating output

type Point3d

type Point3d [3]float64

Point3d is point coordinate in 3D decart system

func LineTriangle3dI1

func LineTriangle3dI1(l0 Point3d, l1 Point3d, t0 Point3d, t1 Point3d, t2 Point3d) (intersect bool, pi []Point3d)

LineTriangle3dI1 return intersection points for case if line and triangle is not on one plane. line intersect triangle in one point

func LineTriangle3dI2

func LineTriangle3dI2(l0 Point3d, l1 Point3d, t0 Point3d, t1 Point3d, t2 Point3d) (intersect bool, pi []Point3d)

LineTriangle3dI2 return intersection points if line and triangle located on one plane. Line on triangle plane Line is not zero ignore triangle point on line

func Mirror3d

func Mirror3d(plane [3]Point3d, points ...Point3d) (mir []Point3d)

func PointLineRatio3d

func PointLineRatio3d(l0 Point3d, l1 Point3d, ratio float64) (p Point3d)

PointLineRatio3d return point in accroding to line ratio

func TriangleTriangle3d

func TriangleTriangle3d(a0 Point3d, a1 Point3d, a2 Point3d, b0 Point3d, b1 Point3d, b2 Point3d) (intersect bool, pi []Point3d)

TriangleTriangle3d return intersection points between two triangles. do not intersect with egdes

type State

type State int64

State is result of intersection

const (

	// VerticalSegment return if segment is vertical
	VerticalSegment State

	// HorizontalSegment return if segment is horizontal
	HorizontalSegment

	// ZeroLengthSegment return for zero length segment
	ZeroLengthSegment

	// Segment A and segment B are parallel.
	// Intersection point data is not valid.
	Parallel

	// Collinear return if:
	// Segment A and segment B are collinear.
	// Intersection point data is not valid.
	Collinear

	// OnSegment is intersection point on segment
	OnSegment

	// OnPoint0Segment intersection point on point 0 segment
	OnPoint0Segment

	// OnPoint1Segment intersection point on point 1 segment
	OnPoint1Segment

	// ArcIsLine return only if wrong arc is line
	ArcIsLine

	// ArcIsPoint return only if wrong arc is point
	ArcIsPoint
)

func (State) Has

func (s State) Has(si State) bool

Has is mean s-State has si-State

func (State) Not

func (s State) Not(si State) bool

Not mean s-State have not si-State

func (State) String

func (s State) String() string

String is implementation of Stringer implementation for formating output

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL