-1

I am working on a task in which I have to project nodes (X and Y coordinates) of a point cloud to the circumference located exactly on the centre of gravity of the mesh (Geometry). My question is how can I create a circumference on the geometry and divvide it into 36 different parts and then how can I project the nodes on it.

What I have done? : I have found the centroid (Centre of Gravity) of the geometry. I moved the geometry with its centroid and placed it on the reference point (0, 0). Now I have the same geometry, but with different coordinates which I have shown here below.

node_number X_coordinate    Y_coordinate
    0            -1.0          -2.0
    1            -1.0          -1.0
    2            -1.0           0.0
    3            -1.0           1.0
    4            -2.0           1.0
    5            -2.0           2.0
    6            -1.0           2.0
    7             0.0           2.0
    8             1.0           2.0
    9             2.0           2.0
   10             2.0           1.0
   11             1.0           1.0
   12             0.0           1.0
   13             0.0           0.0
   14             0.0          -1.0
   15             0.0          -2.0

I would like to project the nodes (coordinates shown above) onto the circumference which is divided into 36 pixels (parts). I have shown an example of that below in the picture.enter image description here:

Urvish
  • 1
  • 1
  • Are you asking which mathematical formula you need to use? – mkrieger1 Aug 20 '22 at 15:39
  • I am asking for a python code and formula also. Because my goal is to make a vector or an array after flattening the circumference which will be having various values of nodes projected. Therefore my first goal is to draw a circumference on the geometry, divide it into 36 equal parts. Then projecting nodes to that circumference. – Urvish Aug 20 '22 at 16:15

1 Answers1

0

Drawing a radius of unit length at angle theta just isn't that hard. Time to hit the books and read up on SohCahToa.

I include a few of your example points. Point m is on the mesh, while point c is on the unit circle.

Notice that you include (0, 0) as a mesh point, and that atan2 arbitrarily chooses an angle of zero for it. You might prefer to throw an exception in this case. Shifting the entire mesh by a small random amount would be one strategy for avoiding the ambiguity.

import math

mesh_points = [
    (-1, -2),
    (-1, -1),
    (0, 0),
    (0, -2),
]


def projection_onto_circle(mesh_points, r=1, epsilon=1e-6):
    """Projects a container of mesh points onto a circle.

    Defaults to using a unit circle.
    Mesh points should be specified w.r.t.
    a suitable origin, e.g. the mesh centroid.
    """
    for x_m, y_m in mesh_points:
        theta = math.atan2(y_m, x_m)
        x_c = r * math.cos(theta)
        y_c = r * math.sin(theta)
        plot(x_c, y_c)
        assert abs(r - math.sqrt(x_c ** 2 + y_c ** 2)) < epsilon


def draw_circle(num_points=36, r=1):
    """Draw equidistant points along the circumference of a circle.
    """
    inc = 360 / num_points
    for i in range(0, num_points + 1):
        deg = i * inc
        theta = math.radians(deg)
        x = r * math.cos(theta)
        y = r * math.sin(theta)
        plot(x, y)


def plot(x, y):
    """Stub, for displaying points on matplotlib axes,
    HTML5 or tk canvas.
    """
    print(f'({x:.03f}, {y:.03f})')
J_H
  • 17,926
  • 4
  • 24
  • 44
  • Thank you for your reply. I would like to know that how can I draw a circle above my geometry and how can I divide that circle with equal parts (36 number of parts). My goal is to project my geometrical coordinates onto that circle and want to make a vector from that circle. – Urvish Aug 21 '22 at 07:32
  • would you please let me know what a function ´projection´ do? – Urvish Aug 21 '22 at 10:15
  • I added docstrings. – J_H Aug 21 '22 at 16:03
  • plot function does only give the coordinates. Should I plot the coordinates which I get from function 'projection_onto_circle' and 'draw_circle'? – Urvish Aug 21 '22 at 17:19
  • "_Stub_" has a technical meaning in this context. https://en.wikipedia.org/wiki/Method_stub In a real app one would expect that the stubbed out function would be replaced with something that interacts with an API mentioned in the """docstring""", cf https://docs.python.org/3/library/turtle.html for an example of using tk canvas. You chose not to offer an MRE, but if you had I would have used the graphic framework that your code specified. https://stackoverflow.com/help/minimal-reproducible-example – J_H Aug 21 '22 at 23:32