Python Forum
Length and direction cosines of lines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Length and direction cosines of lines
#1
Good day,

First time posting, and new to python
I'm trying to get the user to input the number of lines he wants, then input the coordinates for the line ends for each line

say the user enters the number of lines: 10
then how can I prompt him to input the x y coordinates for each line end for each line (10 times for example)
then store those coordinates to do some operations on it like finding each line length and finding each line direction cosines?


thank you!
Reply
#2
The first part of getting the input is rather easy. Here's the code to do so
numberOfLines = input('Enter the number of lines you want: ')

alphabetList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y' ,'Z']
lineDict = {}

for x in range(0, int(numberOfLines)):
    count = 1
    while x > 25:
        x -= 25
        count += 1
    if count > 1:
        label = f'{count}{alphabetList[x]}'
    else:
        label = f'{alphabetList[x]}'
    lineDict.update({label : input(f'Enter the x and y coordinates for line "{label}" separated by commas, for example: 3, -1\n').split(',')})
Here my output from testing it
Output:
Enter the number of lines you want: 10 Enter the x and y coordinates for line "A" separated by commas, for example: 3, -1 10, 1 Enter the x and y coordinates for line "B" separated by commas, for example: 3, -1 2, 9 Enter the x and y coordinates for line "C" separated by commas, for example: 3, -1 0, -35 Enter the x and y coordinates for line "D" separated by commas, for example: 3, -1 -1010, 1 Enter the x and y coordinates for line "E" separated by commas, for example: 3, -1 3, -3i Enter the x and y coordinates for line "F" separated by commas, for example: 3, -1 1, 9 Enter the x and y coordinates for line "G" separated by commas, for example: 3, -1 -4, 70i Enter the x and y coordinates for line "H" separated by commas, for example: 3, -1 5, i Enter the x and y coordinates for line "I" separated by commas, for example: 3, -1 2, -i Enter the x and y coordinates for line "J" separated by commas, for example: 3, -1 1, 0 {'A': ['10', ' 1'], 'B': ['2', ' 9'], 'C': ['0', ' -35'], 'D': ['-1010', ' 1'], 'E': ['3', ' -3i'], 'F': ['1', ' 9'], 'G': ['-4', ' 70i'], 'H': ['5', ' i'], 'I': ['2', ' -i'], 'J': ['1', ' 0']}
You can then cycle through the dictionary and do operations on all the lines. The only thing I haven't tested is using more than 26 lines, so I don't know if that works properly
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Project Direction bclanton50 1 1,301 Jan-06-2022, 11:38 PM
Last Post: lucasbazan
Question How to understand the vector/direction mason321 0 1,083 Dec-14-2021, 10:57 PM
Last Post: mason321
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,707 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Pointer in the right direction? Viking 5 2,677 Apr-22-2020, 06:14 PM
Last Post: Viking
  Some direction needed Patriot1017 3 2,446 Sep-03-2019, 05:44 PM
Last Post: jefsummers
  Practicing using a "flag": please point in right direction magsloo 5 3,038 May-10-2019, 04:58 AM
Last Post: perfringo
  How to create a graph for direction visualization Visiting 2 2,752 Sep-22-2018, 10:49 PM
Last Post: Visiting
  Need tutorial/direction to access shared memory ridshack 2 2,939 Feb-22-2018, 11:24 PM
Last Post: ridshack

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020