# «Geometry classes» byolafhochherz

on 25 Feb'13 12:03 in

This are Classes I am working on to develop a nice Geometry Quark ... one day ... a you need VectorSpace Quark for this

```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105```
```LineND{
var <>positionVector,<>directionVector,<>segment;
*new { arg positionVector,directionVector,segment=false;
^super.newCopyArgs(positionVector,directionVector,segment);
}
*newUsingPoints{arg positionVector1,positionVector2,segment=false;
^super.newCopyArgs(positionVector1,(positionVector2-positionVector1),segment);
}

projectPoint2Line{arg aPoint;
^positionVector+directionVector.proj(aPoint-positionVector);
}
projectPoint2Segment{arg aPoint;
var cp=positionVector+directionVector.proj(aPoint-positionVector);
var o=LineND(aPoint,cp-aPoint);
^this.intersection(o);
}

isOrthogonal{arg aLine; ^directionVector.isOrthogonal(aLine.directionVector);}

isParallel{arg aLine;
var a=this.directionVector.angle(aLine.directionVector);
if((a==pi)||(a==0),{^true},{^false});
}

skewLinesNearestPoints{arg aLine;
var p1 = this.positionVector;
var p2 =  aLine.positionVector;
var d1 = this.directionVector;
var d2 =  aLine.directionVector;
var delta = (sum(d1**2)*sum(d2**2)) - ((d1 <|> d2)**2);
var delta1 = ((d2<|> (p1-p2)) * (d1<|> d2)) - ((d1<|> (p1-p2)) * sum(d2**2));
var delta2 = ((d2<|> (p1-p2)) * sum(d1**2)) - ((d1<|> d2) * (d1<|> (p1-p2)));
var t1 = delta1 / delta;
var t2 = delta2 / delta;

if (this.segment, {
t1=t1.min(1).max(0);
});
if (aLine.segment, {
t2.min(1).max(0);
});
^[p1+(t1*d1), p2+(t2*d2)];
}

intersection{arg aLine;
var p1,p2;
#p1,p2 = this.skewLinesNearestPoints(aLine);
if(p1.dist(p2)<0.00001,{^p1},{^false});
}

prPointAt{arg index,value;
var r=(value/directionVector[index])-(positionVector[index]/directionVector[index]);
^this.getPointOnLine(r);
}

getPointOnLine{arg s;
^(this.positionVector+(s*this.directionVector));
}
}

Plane{
var <>positionVector,<>spanA,<>spanB;
*new { arg positionVector,spanA,spanB;
^super.newCopyArgs(positionVector,
spanA,
spanB)
}

*newUsingPoints{arg positionVector1,positionVector2,positionVector3;
^super.newCopyArgs(positionVector1,
(positionVector2-positionVector1),
(positionVector3-positionVector1));
}

prProjectionScalars{arg aPoint;
var d1 = this.spanA;
var	d2 = this.spanB;
var bp = this.positionVector;
var  a = sum(d1**2);
var  b = (d1<|> d2);
var  d = b;
var  e = sum(d2**2);
var  c = ((aPoint-bp) <|> d1);
var  f =  ((aPoint-bp) <|> d2);
var delta = (a*e)-(b*d) + 0.0;
var alpha = ((c*e)-(b*f)) / delta;
var beta = ((a*f)-(c*d))/delta;
^[alpha,beta]
}

projectionPoint2Plane{arg aPoint;
var alpha,beta;
#alpha,beta=this.prProjectionScalars(aPoint);
^(this.positionVector + (alpha * this.spanA) + (beta * this.spanB));
}

//TODO
//isCrossing{arg aLine;}
//isParallel{arg aPlane;}
//isOrthogonal{arg aLine;}
//crossingPoint{arg aLine;}//returns a positionVector;
//crossingLine{arg aPlane;}//returns a LineND
}```
raw 2934 chars (focus & ctrl+a+c to copy)
reception