Skip to content

Commit

Permalink
area formula finished. now working on adding arc centroids to polygon…
Browse files Browse the repository at this point in the history
… centroid to create polycurve centroids
  • Loading branch information
JohnHeikens committed Oct 9, 2024
1 parent 764c998 commit 124e110
Show file tree
Hide file tree
Showing 29 changed files with 260 additions and 285 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
}
]
}
2 changes: 1 addition & 1 deletion abstract/coordinatesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, origin: Point, x_axis, y_axis, z_axis):
```
"""

self.id = generateID()

self.Origin = origin
self.Xaxis = Vector.normalize(x_axis)
self.Y_axis = Vector.normalize(y_axis)
Expand Down
2 changes: 1 addition & 1 deletion abstract/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, point=None, vector=None, number=None, distance=0.0, diameter=
- `diameter` (any, optional): A diameter associated with the node, useful in structural applications.
- `comments` (str, optional): Additional comments or notes about the node.
"""
self.id = generateID()

self.point = point if isinstance(point, Point) else None
self.vector = vector if isinstance(vector, Vector) else None
self.number = number
Expand Down
4 changes: 2 additions & 2 deletions abstract/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, *args, **kwargs):
rect3 = Rect(Vector(y=8), Vector(x = 4)) # x 0, y 8, width 4, length 0
```
"""
self.id = generateID()


#first half = for position
half:int = len(args) // 2
Expand All @@ -77,7 +77,7 @@ def __init__(self, *args, **kwargs):

Serializable.__init__(self)

self.id = generateID()


def change_axis_count(self,axis_count: int):
self.p0.change_axis_count(axis_count)
Expand Down
2 changes: 1 addition & 1 deletion abstract/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, text: str = None, font_family: 'str' = None, cs='CoordinateSy
- `points` (list): A list of points derived from the text geometry.
- `path_list` (list): A list containing the path data for each character.
"""
self.id = generateID()

self.text = text
self.font_family = font_family or "arial"
self.xyz = cs.Origin
Expand Down
148 changes: 0 additions & 148 deletions abstract/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,154 +216,6 @@ def pitch(vector_1: 'Vector', angle: float) -> 'Vector':
vector_1.y*math.sin(angle) + vector_1.z*math.cos(angle)
)

@staticmethod
def angle_between(vector_1: 'Vector', vector_2: 'Vector') -> float:
"""Computes the angle in degrees between two vectors.
The angle between two vectors is the angle required to rotate one vector onto the other, measured in degrees.
#### Parameters:
- `vector_1` (`Vector`): The first vector.
- `vector_2` (`Vector`): The second vector.
#### Returns:
`float`: The angle in degrees between the input vectors.
#### Example usage:
```python
vector1 = Vector(1, 0, 0)
vector2 = Vector(0, 1, 0)
angle = Vector.angle_between(vector1, vector2)
# 90
```
"""
proj_vector_1 = Vector.to_matrix(vector_1)
proj_vector_2 = Vector.to_matrix(vector_2)
dot_product = Vector.dot_product(vector_1, vector_2)
length_vector_1 = Vector.length(vector_1)
length_vector_2 = Vector.length(vector_2)

if length_vector_1 == 0 or length_vector_2 == 0:
return 0

cos_angle = dot_product / (length_vector_1 * length_vector_2)
cos_angle = max(-1.0, min(cos_angle, 1.0))
angle = math.acos(cos_angle)
return math.degrees(angle)

@staticmethod
def angle_radian_between(vector_1: 'Vector', vector_2: 'Vector') -> float:
"""Computes the angle in radians between two vectors.
The angle between two vectors is the angle required to rotate one vector onto the other, measured in radians.
#### Parameters:
- `vector_1` (`Vector`): The first vector.
- `vector_2` (`Vector`): The second vector.
#### Returns:
`float`: The angle in radians between the input vectors.
#### Example usage:
```python
vector1 = Vector(1, 0, 0)
vector2 = Vector(0, 1, 0)
angle = Vector.angle_radian_between(vector1, vector2)
# 1.5707963267948966
```
"""
return math.acos((Vector.dot_product(vector_1, vector_2)/(Vector.length(vector_1)*Vector.length(vector_2))))

@staticmethod
def angle_between_YZ(vector_1: 'Vector', vector_2: 'Vector') -> float:
"""Computes the angle in degrees between two vectors projected onto the YZ plane (X-axis rotation).
#### Parameters:
- `vector_1` (`Vector`): The first vector.
- `vector_2` (`Vector`): The second vector.
#### Returns:
`float`: The angle in degrees between the input vectors projected onto the YZ plane (X-axis rotation).
#### Example usage:
```python
vector1 = Vector(1, 1, 0)
vector2 = Vector(1, 0, 1)
angle = Vector.angle_between_YZ(vector1, vector2)
# 90
```
"""
dot_product = Vector.dot_product(vector_1, vector_2)
length_vector_1 = Vector.length(Vector(0, vector_1.y, vector_1.z))
length_vector_2 = Vector.length(Vector(0, vector_2.y, vector_2.z))
if length_vector_1 == 0 or length_vector_2 == 0:
return 0

cos_angle = dot_product / (length_vector_1 * length_vector_2)
cos_angle = max(-1.0, min(cos_angle, 1.0))
angle = math.acos(cos_angle)
return math.degrees(angle)

@staticmethod
def angle_between_XZ(vector_1: 'Vector', vector_2: 'Vector') -> float:
"""Computes the angle in degrees between two vectors projected onto the XZ plane (Y-axis rotation).
#### Parameters:
- `vector_1` (`Vector`): The first vector.
- `vector_2` (`Vector`): The second vector.
#### Returns:
`float`: The angle in degrees between the input vectors projected onto the XZ plane (Y-axis rotation).
#### Example usage:
```python
vector1 = Vector(1, 0, 1)
vector2 = Vector(0, 1, 1)
angle = Vector.angle_between_XZ(vector1, vector2)
# 90
```
"""
dot_product = Vector.dot_product(vector_1, vector_2)
length_vector_1 = Vector.length(Vector(vector_1.x, 0, vector_1.z))
length_vector_2 = Vector.length(Vector(vector_2.x, 0, vector_2.z))

if length_vector_1 == 0 or length_vector_2 == 0:
return 0

cos_angle = dot_product / (length_vector_1 * length_vector_2)
cos_angle = max(-1.0, min(cos_angle, 1.0))
angle = math.acos(cos_angle)
return math.degrees(angle)

@staticmethod
def angle_between_XY(vector_1: 'Vector', vector_2: 'Vector') -> float:
"""Computes the angle in degrees between two vectors projected onto the XY plane (Z-axis rotation).
#### Parameters:
- `vector_1` (`Vector`): The first vector.
- `vector_2` (`Vector`): The second vector.
#### Returns:
`float`: The angle in degrees between the input vectors projected onto the XY plane (Z-axis rotation).
#### Example usage:
```python
vector1 = Vector(1, 0, 1)
vector2 = Vector(0, 1, 1)
angle = Vector.angle_between_XY(vector1, vector2)
# 45
```
"""
dot_product = Vector.dot_product(vector_1, vector_2)
length_vector_1 = Vector.length(Vector(vector_1.x, vector_1.y, 0))
length_vector_2 = Vector.length(Vector(vector_2.x, vector_2.y, 0))

if length_vector_1 == 0 or length_vector_2 == 0:
return 0

cos_angle = dot_product / (length_vector_1 * length_vector_2)
cos_angle = max(-1.0, min(cos_angle, 1.0))
angle = math.acos(cos_angle)
return math.degrees(angle)

@staticmethod
def value(vector_1: 'Vector') -> tuple:
"""Returns the rounded values of the vector's components.
Expand Down
16 changes: 11 additions & 5 deletions example/matrixtester.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from pathlib import Path

from geometry.pointlist import PointCloud

sys.path.append(str(Path(__file__).resolve().parents[1]))

Expand All @@ -11,6 +10,7 @@
from geometry.point import Point
from abstract.vector import Vector
from geometry.curve import Arc
from geometry.pointlist import PointCloud

point = Point(1, 2, 3)
point2 : Point = Point([4,3,2])
Expand All @@ -37,10 +37,16 @@
c = Color(23,42,43,255)
print(c.hex)

l1 = Line(Point(1,2), Point(1, 5))
l2 = Arc(Point(1,5), Point(1.8, 6.2), Point(3,7))
l3 = Line(Point(3,7), Point(7,7))

#counter clockwise
l1 = Line(Point(7,7), Point(3, 7))
l2 = Arc(Point(3,7), Point(1.8, 6.2), Point(1,5))
l3 = Line(Point(1,5), Point(1,2))
curve = PolyCurve(l1,l2,l3)

pc = PointCloud([l.start, l.end])
transformed_pointcloud = combined2 * pc
transformed_pointcloud = combined2 * pc

curve.closed = True
area = curve.area
print(area)
32 changes: 32 additions & 0 deletions geometry/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import math
from typing import Self
from abstract.vector import Vector
from packages.helper import generateID
from abstract.serializable import Serializable

Expand Down Expand Up @@ -156,6 +157,37 @@ def angle(self) -> float:
#deg = atan(other side / straight side)
return math.atan2(self.x, self.y)

@staticmethod
def angle_between(vector_1: 'Coords', vector_2: 'Coords') -> float:
"""Computes the angle in degrees between two coords.
The angle between two coords is the angle required to rotate one vector onto the other, measured in degrees.
#### Parameters:
- `vector_1` (`Vector`): The first vector.
- `vector_2` (`Vector`): The second vector.
#### Returns:
`float`: The angle in degrees between the input coords.
#### Example usage:
```python
vector1 = Vector(1, 0, 0)
vector2 = Vector(0, 1, 0)
angle = Vector.angle_between(vector1, vector2)
# 90
```
"""
dot_product = Vector.dot_product(vector_1, vector_2)
length_vector_1 = Vector.length(vector_1)
length_vector_2 = Vector.length(vector_2)

if length_vector_1 == 0 or length_vector_2 == 0:
return 0

cos_angle = dot_product / (length_vector_1 * length_vector_2)
cos_angle = max(-1.0, min(cos_angle, 1.0))
return math.acos(cos_angle)

@staticmethod
def distance_squared(point_1: 'Coords', point_2: 'Coords') -> float:
"""Computes the Euclidean distance between two 3D points.
Expand Down
Loading

0 comments on commit 124e110

Please sign in to comment.