Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Geometry classes
name
code content
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 }
code description
This are Classes I am working on to develop a nice Geometry Quark ... one day ... a you need VectorSpace Quark for this
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change