Comments and answers for "Can I use the local x,y transforms of a plane?"
http://answers.unity.com/questions/1468194/can-i-use-the-local-xy-transforms-of-a-plane.html
The latest comments and answers for the question "Can I use the local x,y transforms of a plane?"Comment by OllieCJ on OllieCJ's answer
http://answers.unity.com/comments/1468534/view.html
This is superb, precisely what I was after - thank you!Wed, 14 Feb 2018 14:15:15 GMTOllieCJComment by TreyH
http://answers.unity.com/comments/1468348/view.html
Oh, so you're trying to basically tilt the plane that those points are on and the circle with it?Wed, 14 Feb 2018 03:28:26 GMTTreyHComment by Bunny83
http://answers.unity.com/comments/1468332/view.html
Note that if you really want to use 2d coordinates all you need is to define two basis vectors of your 2d space. A plane by itself is not a coordinate system. As first basis vector you can simply use one of the relative vectors between two of your points. To get the second you just use the cross product between your first basis vector and your normal vector. To get the normal vector you just take the cross product between your two relative vectors between your 3 points.
<br>
Once you have your two basic vectors you simply convert all points into relative points (use the first point as origin) and project them onto your basis vectors using the dot product. The two numbers you get from each 3d point are your 2d coordinates. To get back 3d coordinates, just multiply each component with the corresponding basis vector.
<br>
var v0 = points[1] - points[0];
var v1 = points[2] - points[0];
var n = Vector3.Cross(v0, v1).normalized;
// 2d system
var bx = v0.normalized;
var by = Vector3.Cross(v0, n).normalized;
var origin = points[0];
// 3d --> 2d
for (int i = 0; i < points.Length; i++)
{
var relativeP = points[i] - origin;
localPoints[i] = new Vector2(Vector3.Dot(bx, relativeP), Vector3.Dot(by, relativeP));
}
// 2d --> 3d
for (int i = 0; i < points.Length; i++)
{
var p = localPoints[i];
points[i] = origin + bx * p.x + by * p.y;
}Wed, 14 Feb 2018 02:14:19 GMTBunny83Answer by Bunny83
http://answers.unity.com/answers/1468317/view.html
You shouldn't bother with converting the points into 2d coordinates. Just using some vector math you can directly calculate the circle center point. In the process you also get the normal of the plane the circle is located in. I quickly created this method:
public static Vector3 CircleCenter(Vector3 aP0, Vector3 aP1, Vector3 aP2, out Vector3 normal)
{
// two circle chords
var v1 = aP1 - aP0;
var v2 = aP2 - aP0;
normal = Vector3.Cross(v1,v2);
if (normal.sqrMagnitude < 0.00001f)
return Vector3.one * float.NaN;
normal.Normalize();
// perpendicular of both chords
var p1 = Vector3.Cross(v1, normal).normalized;
var p2 = Vector3.Cross(v2, normal).normalized;
// distance between the chord midpoints
var r = (v1 - v2) * 0.5f;
// center angle between the two perpendiculars
var c = Vector3.Angle(p1, p2);
// angle between first perpendicular and chord midpoint vector
var a = Vector3.Angle(r, p1);
// law of sine to calculate length of p2
var d = r.magnitude * Mathf.Sin(a * Mathf.Deg2Rad) / Mathf.Sin(c*Mathf.Deg2Rad);
if (Vector3.Dot(v1, aP2-aP1)>0)
return aP0 + v2 * 0.5f - p2 * d;
return aP0 + v2 * 0.5f + p2 * d;
}
It returns the 3d center position of the circle as well as the plane normal the circle is located in. I simply used it like this inside Update: p0, p1, p2 and C are Transform references to 4 sphere objects.
// inside update
Vector3 norm;
var center = CircleCenter(p0.position, p1.position, p2.position, out norm);
if (!float.IsNaN(center.x))
{
C.position = center;
var r = p0.position - center;
int count = 100;
var q = Quaternion.AngleAxis(360f/count, norm);
for(int i = 0; i < count; i++)
{
var p = r;
r = q * r;
Debug.DrawLine(center+p,center+r, Color.yellow);
}
}
The result looks like this:
<img src="https://www.dropbox.com/s/lst11oscgfs672h/CalculateCircleCenter.gif?raw=1">Wed, 14 Feb 2018 01:54:06 GMTBunny83Comment by OllieCJ on OllieCJ's comment
http://answers.unity.com/comments/1468318/view.html
Thankyou for your answer @TreyH , I am aware of the above; what I'm doing is creating a circle in 3D space, so one that can be at any orientation (think a frisbee on a tilt).
<br>
In order to do that I'm using a calculation based on a 2D circle, then rotating it; to do this I'm trying to create a new coordinate system based on the plane created by three points, I hope that clarifies my question.Tue, 13 Feb 2018 22:04:07 GMTOllieCJComment by TreyH
http://answers.unity.com/comments/1468346/view.html
Three points on a plane can only determine a circle, and that is with the requirement that those 3 points do not lie on the same line. You cannot get a unique sphere from 3 coplanar points; that requires *4* points.
----------
edit Derivations:
- 3-Point circle: http://mathforum.org/library/drmath/view/55233.html
- 4-Point sphere: https://math.stackexchange.com/questions/894794/sphere-equation-given-4-pointsTue, 13 Feb 2018 19:50:03 GMTTreyH