summaryrefslogtreecommitdiff
path: root/cad/src/tools/FindLength.py
blob: cc6b6beb942c0b728b488f69b6fcb7e87f49321f (plain)
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
#!/usr/bin/env python

# Copyright 2008 Nanorex, Inc.  See LICENSE file for details. 

"""
Find the length of a vector, given the coordinates of the two ends.
The 2D vectors are offset by a constant Z amount, and one is rotated
by a constant angle.

"""

import sys
import math

dtheta = -36.0 * math.pi / 180.0

s = math.sin(dtheta)
c = math.cos(dtheta)

while True:
    line = sys.stdin.readline()
    if (not line):
        break
    splitLine = line.split()
    x1 = float(splitLine[0])
    y1 = float(splitLine[1])

    x2i = float(splitLine[2])
    y2i = float(splitLine[3])

    x2 = x2i * c - y2i * s
    y2 = x2i * s + y2i * c

    dx = x1 - x2
    dy = y1 - y2
    dz = 0.318

    length = math.sqrt(dx * dx + dy * dy + dz * dz)

    print "(%f %f) -> (%f %f) %6.2f" % (x1, y1, x2, y2, length * 1000)