Documentation ¶
Index ¶
- Constants
- Variables
- func AngleBetween(center, from, mid, to, a Point) (res bool)
- func Arc(Arc0 Point, Arc1 Point, Arc2 Point) (xc float64, yc float64, r float64)
- func ArcSplitByPoint(Arc0 Point, Arc1 Point, Arc2 Point, pi ...Point) (res [][3]Point, err error)
- func Area(tr0 Point, tr1 Point, tr2 Point) float64
- func Check(pps ...Point) error
- func Distance(p0 Point, p1 Point) float64
- func Distance128(p0, p1 Point) float64
- func Distance3d(p0 Point3d, p1 Point3d) float64
- func Line(p0 Point, p1 Point) (A float64, B float64, C float64)
- func LineArc(Line0 Point, Line1 Point, Arc0 Point, Arc1 Point, Arc2 Point) (pi []Point, stA State, stB State)
- func LineLine(pa0 Point, pa1 Point, pb0 Point, pb1 Point) (pi []Point, stA State, stB State)
- func LineLine3d(a0 Point3d, a1 Point3d, b0 Point3d, b1 Point3d) (ratioA float64, ratioB float64, intersect bool)
- func Linear(a11 float64, a12 float64, b1 float64, a21 float64, a22 float64, b2 float64) (x float64, y float64, err error)
- func MirrorLine(sp0, sp1 Point, mp0, mp1 Point) (ml0 Point, ml1 Point, err error)
- func Plane(p1 Point3d, p2 Point3d, p3 Point3d) (A float64, B float64, C float64, D float64)
- func PointArc(pt Point, Arc0 Point, Arc1 Point, Arc2 Point) (pi []Point, stA, stB State)
- func PointInCircle(point Point, circle [3]Point) bool
- func PointLine(pt Point, pb0 Point, pb1 Point) (pi []Point, stA State, stB State)
- func PointLine3d(p Point3d, l0, l1 Point3d) (intersect bool)
- func PointLineDistance(pc Point, p0 Point, p1 Point) (distance float64)
- func PointOnPlane3d(A float64, B float64, C float64, D float64, p Point3d) (on bool)
- func PointPoint(pt0 Point, pt1 Point) (pi []Point, stA State, stB State)
- func PointPoint3d(p0 Point3d, p1 Point3d) (intersect bool)
- func PointTriangle3d(p Point3d, t0 Point3d, t1 Point3d, t2 Point3d) (intersect bool)
- func PowE2(x float64) float64
- func PowE3(x float64) float64
- func PowE4(x float64) float64
- func PowEn(x float64, e int) float64
- func SamePoints(p0 Point, p1 Point) bool
- func SamePoints3d(p0 Point3d, p1 Point3d) bool
- func TriangleSplitByPoint(pt Point, tr0 Point, tr1 Point, tr2 Point) (res [][3]Point, lineIntersect int, err error)
- func ZeroLine3d(l0 Point3d, l1 Point3d) (zero bool)
- func ZeroTriangle3d(t0 Point3d, t1 Point3d, t2 Point3d) (zero bool)
- type Mesh
- func (mesh *Mesh) AddLine(inp1, inp2 Point) (err error)
- func (mesh *Mesh) AddPoint(p Point, tag int) (idp int, err error)
- func (mesh *Mesh) Check() (err error)
- func (mesh *Mesh) Clockwise()
- func (mesh *Mesh) Compile(model *Model) (err error)
- func (mesh *Mesh) Delanay(tri ...int) (err error)
- func (mesh *Mesh) GetMaterials(ps ...Point) (materials []int, err error)
- func (mesh *Mesh) Materials() (err error)
- func (mesh *Mesh) Model() *Model
- func (mesh *Mesh) Smooth(pts ...int) (err error)
- func (mesh *Mesh) Split(d float64) (err error)
- type Model
- func (m *Model) AddArc(start, middle, end Point, tag int)
- func (m *Model) AddCircle(xc, yc, r float64, tag int)
- func (m *Model) AddLine(start Point, end Point, tag int)
- func (m *Model) AddModel(from Model)
- func (m *Model) AddMultiline(tag int, ps ...Point)
- func (m *Model) AddPoint(p Point) (index int)
- func (m *Model) AddTriangle(start, middle, end Point, tag int)
- func (m *Model) ArcsToLines()
- func (m *Model) ConvexHullTriangles()
- func (m *Model) Copy() (dst Model)
- func (m *Model) Dxf() string
- func (m *Model) Intersection()
- func (m *Model) JSON() (_ string, err error)
- func (m *Model) Merge(from Model)
- func (m *Model) MinPointDistance() (distance float64)
- func (m *Model) Move(dx, dy float64)
- func (m *Model) Read(filename string) (err error)
- func (m *Model) RemoveEmptyPoints()
- func (m *Model) RemovePoint(remove func(p Point) bool)
- func (m *Model) Rotate(xc, yc, angle float64)
- func (m *Model) Split(d float64)
- func (m *Model) String() string
- func (m *Model) TagProperty() (length []float64, area []float64)
- func (m *Model) Write(filename string) (err error)
- type OrientationPoints
- type Point
- type Point3d
- func LineTriangle3dI1(l0 Point3d, l1 Point3d, t0 Point3d, t1 Point3d, t2 Point3d) (intersect bool, pi []Point3d)
- func LineTriangle3dI2(l0 Point3d, l1 Point3d, t0 Point3d, t1 Point3d, t2 Point3d) (intersect bool, pi []Point3d)
- func Mirror3d(plane [3]Point3d, points ...Point3d) (mir []Point3d)
- func PointLineRatio3d(l0 Point3d, l1 Point3d, ratio float64) (p Point3d)
- func TriangleTriangle3d(a0 Point3d, a1 Point3d, a2 Point3d, b0 Point3d, b1 Point3d, b2 Point3d) (intersect bool, pi []Point3d)
- type State
Constants ¶
const ( CollinearPoints OrientationPoints = -1 ClockwisePoints = 0 CounterClockwisePoints = 1 )
const ( // Boundary edge Boundary = -1 // Removed element Removed = -2 // Undefined state only for not valid algorithm Undefined = -3 Fixed = 100 Movable = 200 )
const Eps3D = 1e-5
Eps3D is default epsilon for 3D operations
Variables ¶
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") )
var (
// Eps is epsilon - precision of intersection
Eps = 1e-10
)
Functions ¶
func AngleBetween ¶
AngleBetween return true for angle case from <= a <= to
func ArcSplitByPoint ¶
ArcSplitByPoint return points of arcs with middle point if pi is empty or slice of arcs.
DO NOT CHECKED POINT ON ARC
func Distance128 ¶
Distance128 is distance between 2 points with 128-bit precisions
func Distance3d ¶
Distance3d is distance between 2 points in 3D
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 ¶
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 ¶
MirrorLine return intersection point and second mirrored point from mirror line (mp0-mp1) and ray (sp0-sp1)
func PointInCircle ¶
PointInCircle return true only if point inside circle based on 3 circles points
func PointLine3d ¶
PointLine3d return true only if point located on line segment
func PointLineDistance ¶
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 PointPoint ¶
PointPoint return states between two points.
func PointPoint3d ¶
PointPoint3d return true only if points have same coordinate
func PointTriangle3d ¶
PointTriangle3d return true only if point located inside triangle but do not check point on triangle edge
func SamePoints ¶
SamePoints return true only if point on very distance or with same coordinates
func SamePoints3d ¶
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 ¶
ZeroLine3d return true only if lenght of line segment is zero
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 (*Mesh) Clockwise ¶
func (mesh *Mesh) Clockwise()
Clockwise change all triangles to clockwise orientation
func (*Mesh) GetMaterials ¶
GetMaterials return materials for each point
func (*Mesh) Materials ¶
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
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 (*Model) AddMultiline ¶
AddMultiline add many lines with specific tag
func (*Model) AddTriangle ¶
AddTriangle add triangle into model with specific tag/material
func (*Model) ConvexHullTriangles ¶
func (m *Model) ConvexHullTriangles()
ConvexHullTriangles add triangles of model convex hull
func (*Model) Dxf ¶
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) MinPointDistance ¶
MinPointDistance return minimal between 2 points
func (*Model) RemoveEmptyPoints ¶
func (m *Model) RemoveEmptyPoints()
RemoveEmptyPoints removed point not connected to line, arcs, triangles
func (*Model) RemovePoint ¶
RemovePoint removed point in accoding to function `filter`
func (*Model) TagProperty ¶
TagProperty return length of lines, area of triangles for each tag. Arcs are ignored
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 ¶
ConvexHull return chain of convex points
func MiddlePoint ¶
MiddlePoint calculate middle point precisely.
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 PointLineRatio3d ¶
PointLineRatio3d return point in accroding to line ratio
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 )