I am trying to use numpy-stl to extract the vertices from an stl model to use for coherent point drift registration. How do you go about extracting the vertices? I understand how to create a mesh from a list of vertices and faces, but not how to go backwards.
I've tried: Creating a new mesh from vertices and faces. Importing created mesh.
Let's take a .stl file of a cuboid with length 100, width 200, height 300.
from stl import mesh
import numpy as np
cuboid = mesh.Mesh.from_file("./cuboid.stl")
points = np.around(np.unique(cuboid.vectors.reshape([cuboid.vectors.size/3, 3]), axis=0),2)
print "Points are", points.tolist()
Output:
Points are [[0.0, 0.0, 0.0], [0.0, 0.0, 300.0], [0.0, 200.0, 0.0], [0.0, 200.0, 300.0], [100.0, 0.0, 0.0], [100.0, 0.0, 300.0], [100.0, 200.0, 0.0], [100.0, 200.0, 300.0]]
Related
I have a JSON field which have the following data:
[{"low": 57.07, "rsi": 0.0, "date": 1675935000000, "high": 57.07, "open": 57.07, "close": 57.07, "ema_7": 0.0, "ema_21": 0.0, "symbol": "ACPL", "volume": 0, "SUPERT_10_1_0": 0.0, "SUPERTd_10_1_0": 1, "SUPERTl_10_1_0": 0.0, "SUPERTs_10_1_0": 0.0}, {"low": 57.0, "rsi": 0.0, "date": 1675935900000, "high": 58.49, "open": 57.07, "close": 58.4, "ema_7": 0.0, "ema_21": 0.0, "symbol": "ACPL", "volume": 2500, "SUPERT_10_1_0": 0.0, "SUPERTd_10_1_0": 1, "SUPERTl_10_1_0": 0.0, "SUPERTs_10_1_0": 0.0}, {"low": 57.7, "rsi": 0.0, "date": 1675936800000, "high": 58.5, "open": 58.4, "close": 58.49, "ema_7": 0.0, "ema_21": 0.0, "symbol": "ACPL", "volume": 27000, "SUPERT_10_1_0": 0.0, "SUPERTd_10_1_0": 1, "SUPERTl_10_1_0": 0.0, "SUPERTs_10_1_0": 0.0}, {"low": 58.15, "rsi": 0.0, "date": 1675937700000, "high": 59.5, "open": 58.5, "close": 59.5, "ema_7": 0.0, "ema_21": 0.0, "symbol": "ACPL", "volume": 41000, "SUPERT_10_1_0": 0.0, "SUPERTd_10_1_0": 1, "SUPERTl_10_1_0": 0.0, "SUPERTs_10_1_0": 0.0}, {"low": 59.0, "rsi": 0.0, "date": 1675938600000, "high": 59.5, "open": 59.5, "close": 59.0, "ema_7": 0.0, "ema_21": 0.0, "symbol": "ACPL", "volume": 2500, "SUPERT_10_1_0": 0.0, "SUPERTd_10_1_0": 1, "SUPERTl_10_1_0": 0.0, "SUPERTs_10_1_0": 0.0}]
The following query perfectly works for me:
SELECT indicators_15.symbol,indicators_15.open,indicators_15.close
FROM indicators_15,
JSON_TABLE(data, '$[*]' COLUMNS (
close DOUBLE PATH '$.close',
open DOUBLE PATH '$.open')
) indicators_15;
but my Hosting, Namecheap is using an older version of MariaDB hence it is failing. How can I come up with an equivalent non-JSON_TABLE version?
Below is the desired output:
To do this in an old version of MariaDB you need a table of numbers.
CREATE TABLE numbers ( number INT UNSIGNED PRIMARY KEY );
INSERT INTO numbers (number) VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
Insert more numbers as needed, up to the maximum length of any of your JSON arrays.
Then you can use these numbers to extract the n-th entry from your JSON array.
SELECT i.symbol,
JSON_EXTRACT(i.data, CONCAT('$[', o.number, '].open')) AS open,
JSON_EXTRACT(i.data, CONCAT('$[', o.number, '].close')) AS close
FROM indicators_15 AS i
JOIN numbers AS o ON o.number < JSON_LENGTH(i.data);
Dbfiddle using MariaDB 10.5.
Let me know if this is not clear to you and I'll try to explain further.
This really demonstrates what a bad idea it is to use JSON in a relational database. There is no reason to use JSON in your example, because every array entry has the same fields. Use JSON if you can't predict the fields. Use normal rows and columns if the fields are the same in every record. Using JSON where it is not needed — when the developer can't understand how to use it or if you are constrained to use an old version of the software that doesn't have enough support for JSON functions — will only harm your software project by increasing time to develop and therefore increasing development costs.
I have a JSON file that contains the geometric information about the sketch. The file is in the following format:
"Name": Name of the geometric entity
"Type": Type of the entity, either a line or an arc (a circle is represented by an arc and a rectangle as a set of 4 such dictionaries of type line.)
If the entity is of the type line, then the dict would contain the coordinates of the starting and ending points of the line.
If it is of the type arc, then the dict would contain the radius, the coordinates of the center and the starting and ending points of the arc.
Here is an example of each type:
Type == Line
"Name": "Line8",
"Type": "Line",
"Start Point": [
0.0,
-13.694950218796503,
127.7623417068559
],
"End Point": [
0.0,
-12.800696621739458,
121.82935674950514
],
"Length": 5.999999999999998
Type == Arc
"Name": "Arc4",
"Type": "Arc",
"CentrePoint": [
0.0,
0.0,
0.0
],
"Radius": 137.0,
"RotationAngle": 0.0,
"StartAngle": 1.5474413367198918,
"EndAngle": 1.5941513168699013,
"Circumference": 6.399267280551308
A JSON file will contain multiple such dictionaries for multiple geometric entities that make up a geometric sketch.
I want to create a bounding box around that sketch and need its coordinates.
My initial approach was to just take the min and max values of the x, y and z coordinates from these dictionaries to define a bounding box. But by doing this I might end up missing the curves in the arcs since I only have information about the center of the arc and not the points on the arc.
How should I go about getting the bounding box coordinates given this JSON file?
I am working with the rigged figure gltf:
Not to post the entire gltf, i will post the relevant nodes:
{
"children": [
21,
1
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"name": "Z_UP"
},
{
"mesh": 0,
"skin": 0,
"name": "Proxy"
},
...
{
"translation": [
0.0,
0.06650590896606446,
0.0
],
"rotation": [
4.2157907720330458e-10,
0.9999844431877136,
-0.005583992227911949,
-7.549667913053783e-8
],
"scale": [
1.0,
1.0000001192092896,
1.0
],
"name": "neck_joint_2"
},
{
"children": [
2
],
"name": "Armature"
}
So node 0 is the parent of node 1 and node 21. However the skin in node 1 has it's joints starting at node 2. i.e. the skin in node 1 is the "parent" of the skeleton defined by the nodes from 2 to 21.
The question is then, should the transformation in node 0 be applied twice to the nodes in the skin?
From glTF Specifications — Skins...
Client implementations should apply only the transform of the skeleton root node to the skinned mesh while ignoring the transform of the skinned mesh node.
So in this sample, the inherited world transform of Node 1 is not applied to the joints/bones of the skin. In other words, the node-skin relationship does not apply any transformation to the joints of the skin.
I have some JSON data that conveys some information about something. The information also includes location (for example location of a business). Now within the JSON file, can I specify the location as a polygon in the following manner? Am I doing anything wrong here (specially notice the "location"):
.....
"location":
{
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
}
.....
I've been working with a 2 column system so far but feel I'm needing a third and that 3 spread across the screen doesn't give much of a view without adjusting the width every time.
It's there a way to get the grid layout but have the bottom half of the screen one file.
I know it's a long shot but wondering if anyone knows of anything
Found that you can edit for custom layouts in Packages/default/Main.sublime-menu
Having problems saving though error in trying to parse file: expected value in ~/library/application support/sublime text 2/packages/default/Main.sublime-menu:407:21
Edited: for better layout
Found something that is similar, been trying to mod it but don't understand how the cells work
This one is similar
"args":
{
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 0.5, 1.0],
"cells": [
[0, 0, 1, 2], // (0.0, 0.0) -> (0.5, 1.0)
[1, 0, 2, 1], // (0.5, 0.0) -> (1.0, 0.5)
[1, 1, 2, 2] // (0.5, 0.5) -> (1.0, 1.0)
]
}
which gives
Assuming these are just coordinates with 0,0 at the upper left, something like this should work:
[0, 0, 1, 1],
[1, 0, 2, 1],
[0, 1, 2, 2]
Edit: Just tested, and it does.
Create the file Main.sublime-menu in your Packages > User folder (best to leave the default menu alone) and put the following code in it:
[{
"id": "view",
"children": [{
"id": "layout",
"children": [{
"command": "set_layout",
"caption" : "Custom: 3 Pane",
"mnemonic": "C",
"args": {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 0.5, 1.0],
"cells": [
[0, 0, 1, 1],
[1, 0, 2, 1],
[0, 1, 2, 2]
]
}
}]
}]
}]
You will see Custom: 3 Pane in your layout options. No need to restart Sublime Text.
For anyone interested, here is a gist containing this layout as well as a flipped version.
This was very helpful for visualizing what points the coordinates are referring to: http://www.sublimetext.com/forum/viewtopic.php?f=6&t=7284&start=0&hilit=set+layout