Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
All lines have the same short point A. find the other end point and sort it anticlockwise 1, 2, 3, 4, 5
Solved! Go to Solution.
All lines have the same short point A. find the other end point and sort it anticlockwise 1, 2, 3, 4, 5
Solved! Go to Solution.
first of all, you need to convert Decart (Cartesian) coordinates (X,Y,Z) to Spherical coordinates (r,phi, theta). Spherical - is a 3D variant of polar coordinates.
then, you have to sort your array of spherical coordinates by "phi" (phi[i] < phi[i+1] = counterclockwise. phi[i] > phi[i+1] = clockwise. if you have two points with the same phi, compare "r" and "theta" values).
and when sort is done, you can convert polar coordinates of your sorted array back to decart.
/*
DECART
AcGePoint3d::x - X
AcGePoint3d::y - Y
AcGePoint3d::z - Z
SPHERICAL
AcGePoint3d::x - r
AcGePoint3d::y - phi
AcGePoint3d::z - theta
*/
AcGePoint3d Decart2Spherical(AcGePoint3d c)
{
AcGePoint3d p;
p.x=sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
p.y=acos(c.x/sqrt(c.x*c.x+c.y*c.y))*(c.y>=0?1:-1);
p.z=acos(c.z/p.x);
return p;
}
AcGePoint3d Spherical2Decart(AcGePoint3d p)
{
decart d;
d.x=p.x*cos(p.y)*sin(p.z);
d.y=p.x*sin(p.y)*sin(p.z);
d.z=p.x*cos(p.z);
return d;
}almost forgot. may be, before convertation you will need to subtract "A" coords from the rest points, to make "A" a zero point and append "A" after Spheriacal2Decart. In most cases it's unnecessary, but who knows 🙂
Hm... i have found 2 mistakes in my post:
1. i forgot to change "decart" variable to "AcGePoint3d" variable at Spherical2Decart function, but it's not hard to understand it looking through the rest code and change it at your side.
2. phi[i] < phi[i+1] = clockwise. phi[i] > phi[i+1] = counterclockwise, that will be correct. this mistake can be fixed at your side too, by changing a sign ">" to "<" after code running and analyze the result.
that's all. so, if "this algorithm doesn't work" can you provide your code?
I've created a sample project for demonstration. May be i did something wrong, but i cant attach a screencast video. So, the link to it is below
https://knowledge.autodesk.com/ru/community/screencast/8b3bdff1-82c2-478e-b9e7-2481ddc03c7c
@463017170 написал (-а):If the plane is rotated to this point, the result of the algorithm is wrong.
no one told it would be easy :).
you have to transform coordinates according to current view before decart-polar and after polar-decart converting (reverse converting is necessary, if you need points in WCS).