Rhinoscript, Perpendicular bisector

This code returns the perpendicular bisector of two points. Perpendicular bisectors and in general bisectors are very useful for triangle and circles manipulation.

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
Option Explicit
'Script version miƩrcoles, 11 de marzo de 2009 13:55:14

Call PerpBisector()
Sub PerpBisector()
 
	Dim p1, p2, mid
 
	p1 = Rhino.getpoint()
	p2 = rhino.getpoint()
 
	rhino.addpoints(array(p1, p2))
 
	mid = CalcMidPt(p1, p2)
 
	'vector zone
	Dim Ovec, PerpVec, Ovec2, PerpVec2, Sp, Ep
 
	Ovec = Rhino.VectorCreate(p2, p1)
	PerpVec = rhino.VectorCrossProduct(Ovec, Array(0, 0, 1))
 
	Ovec2 = Rhino.VectorCreate(p1, p2)
	PerpVec2 = Rhino.VectorCrossProduct(Ovec2, Array(0, 0, 1))
 
	PerpVec = Rhino.VectorUnitize(PerpVec)
	PerpVec2 = Rhino.VectorUnitize(perpVec2)
 
 
	PerpVec = Rhino.VectorScale(PerpVec, 10)
	PerpVec2 = Rhino.VectorScale(perpVec2, 10)
 
	Sp = Rhino.PointAdd(mid, PerpVec)
	Ep = Rhino.PointAdd(mid, PerpVec2)
 
	rhino.addline Sp, Ep
 
End Sub
 
Function CalcMidPt(a, b)
	CalcMidPt = Array((a(0) + b(0)) / 2, (a(1) + b(1)) / 2, 0)
End Function

Leave a Reply