-1

Two angles in degrees are given. From these, I would like to calculate the resulting vector and also to plot it. the modulus / length can be a fixed value. It should start at point 0,0,0

The plot should display the axes as follows: enter image description here

My current code looks as follows:

import matplotlib.pyplot as plt
import math as Math

alpha = 2
beta = 0
r = 5 # scalar length

x = Math.cos(alpha) * Math.cos(beta) * r;
z = Math.sin(alpha) * Math.cos(beta) * r;
y = Math.sin(beta) * r;

u = [x, y, z]

fig = plt.figure()
ax = plt.axes(projection = '3d')

ax.set_xlim([0,10])
ax.set_ylim([0, 10])
ax.set_zlim([0,10])

start = [0,0,0]

ax.quiver(start[0], start[1], start[2], u[0], u[1], u[2], color='r', linewidth=2)

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('test');

ax.view_init(6,10)

So at the moment I am not sure how to display the coordinate system like in the image. And also I am not sure how to calculate the vector correctly.

Liris
  • 1,399
  • 3
  • 11
  • 29
Adler Müller
  • 248
  • 1
  • 14
  • 1
    Your code sample is not runnable because there is multiple typos. Please fix this before anyone can/wants to have a look. The simplest is to **directly** copy/paste a [minimal working example](https://stackoverflow.com/help/minimal-reproducible-example) that runs on your computer. – Liris Aug 11 '21 at 07:46
  • I have fixed the typos. Code is already as simple as possible. – Adler Müller Aug 11 '21 at 07:58
  • There was a remaining typo ... I submitted an edit to correct it, but it highlights that you did not run the code you gave here. Calculating the sum of two vectors is simply the sum of their coordinates, and I suggest you have a look on the numpy library, very nice to handle vector calculations. – Liris Aug 11 '21 at 08:52
  • For the position of the axes, look [here](https://stackoverflow.com/questions/50493036/changing-position-of-axes-in-axes3d) – Liris Aug 11 '21 at 08:54
  • *Calculating* the vector and *plotting* the vector are two entirely separate problems. (I am good at mathematics but know nothing about Python.) – Beta Aug 11 '21 at 12:05
  • By the diagram I think you mean your coordinate system are at an angle instead of 90 degrees. ????? –  Sep 29 '21 at 06:58

1 Answers1

0

By the diagram I think you mean your coordinate system are at an angle instead of 90 degrees. ????? - or - the alpha and beta angles are the angle which your resultant vector makes with x and y axis , then

x = cos(alpha)*cos(beta)
y = sin(alpha)*cos(beta)
z = sin(beta)