[Python] Find coordinates from two angles and distance

Overview

In an object that has a parent-child relationship It can be used when the child object moves when the parent object rotates.

Reference code

Execution environment: Motionbuilder 2015

I made a process to draw a sphere with Null in MB. The main processing is only the contents of getPosition ().

# -*- coding: utf-8 -*-

from pyfbsdk import *
import math

#Method to find coordinates from two angles and distance
def getPosition(_angle1, _angle2, _radius):
    x = _radius * math.sin(math.radians(_angle1)) * math.cos(math.radians(_angle2));
    y = _radius * math.sin(math.radians(_angle1)) * math.sin(math.radians(_angle2));
    z = _radius * math.cos(math.radians(_angle1));
    return FBVector3d(x, y, z);

#If you change this for software for the software you want to use, it will draw a sphere.
## angle1,You can also draw a semicircle by adjusting the value that goes into angle2
##Note that executing step of the third argument of range with 1 (or not specified) is heavy.
parentPos = FBVector3d(50, 50, 50)
for angle1 in range(0, 360, 3):
    for angle2 in range(0, 180, 3):
        mdlNull = FBModelNull("Null_{0}_{1}".format(str(angle1), str(angle2)))
        mdlNull.Show = True
        mdlNull.Scaling = FBVector3d(1, 1, 1)
        mdlNull.Translation = parentPos + getPosition(angle1, angle2, 100.0)

When you run it, you will get something like this. (This made the step of range () in 1!)

球体.png

Recommended Posts

[Python] Find coordinates from two angles and distance
geometry> 2017-03-31: Find the distance from two latitudes and longitudes> Use Haversine formula | 2019-01-08 Vincenty method
Python, yield, return, and sometimes yield from
Read and use Python files from Python
Find the Levenshtein Distance with python
About Python, from and import, as
Find the distance from latitude and longitude (considering the roundness of the earth).
Find all paths between two points from an adjacency matrix in python
From Python to using MeCab (and CaboCha)
Porting and modifying doublet-solver from python2 to python3.
Find and check inverse matrix in Python
Python --Read data from a numeric data file and find the multiple regression line.
Find the position in the original image from the coordinates after affine transformation (Python + OpenCV)
Distance calculation between two latitude and longitude points with python (using spherical trigonometry)
Firebase: Use Cloud Firestore and Cloud Storage from Python
Study from Python Reading and writing Hour9 files
[Python] How to read data from CIFAR-10 and CIFAR-100
Load and execute command from yml in python
PHP and Python integration from scratch on Laravel
Explanation of edit distance and implementation in Python
Generate and output plantuml object diagram from Python object
sql from python
MeCab from Python
Control other programs from Python (communication between Python and exe)
[Python beginner] Extract prefectures and cities from addresses (3 lines).
Find the part that is 575 from Wikipedia in Python
Find the Hermitian matrix and its eigenvalues in Python
Get mail from Gmail and label it with Python3
Get files from Linux using paramiko and scp [Python]
[Python] Extract only numbers from lists and character strings
[Python] Start a batch file from Python and pass variables.
Python --Read data from a numeric data file to find the covariance matrix, eigenvalues, and eigenvectors