objective c - 2D Point, to 3D, then back to 2D -
figure 1: drawing bezier on layer in 2d (coregraphics), have point & b.
figure 2: can rotate layer approximately 70 degrees.
figure 3: want know points & b now, somehow squishing image 3d 2d.
what i'd ideally want create function this:
-(cgpoint)calculatenewpointfrom:(cgpoint)p withangle:(float)angle { //rotate point angle in 3d space //return new point in 2d space } all help welcome. thanks
if have coordinates of point q in 3d: (x, y, z)
and want project onto plane contains point p , has normal vector n,
the equation of plane
(r - p) . n = 0 where utilize vector subtraction, , . dot product.
from can deduce projection of point onto plane: draw line along normal vector n until intersects plane.
so there value a such that
q + * n lies in plane, i.e.
(q - * n - p) . n = 0 solving (notice n . n = 1 ):
a = (q - p) . n (notice - "normal distance" q p; no coincidence!)
the value of point intersect now
q + ((q - p) . n ) * n notice 1 time again - using vector math, lastly *n results in 3 values (since n 3d vector).
you can generalize if trying create non-normal projection onto plane (for example, want project onto xy plane, "looking @ angle"). in case, need project along different direction m (the direction looking), , equation of intersection becomes
q + ((q - p) . n ) * m / (m . n) as can see, if m perpendicular n (you looking along plane, rather @ it), there no solution...
you can see if making projection straight onto xy plane n = [0 0 1]), whole thing simplifies setting z=0
let me know if enough, or if need actual lines of code...
--- edit --- adding simple code:
if have series of points (x, y) describe curve, can rotate z axis (perpendicular plane) angle θ following:
x1 = x * cos(theta) - y * sin(theta); y1 = x * sin(theta) + y * cos(theta); now can "squish" these points appears looking @ them side, reducing y coordinates:
x2 = x1; y2 = y1 * cos(alpha); where alpha apparent angle looking @ curve. if looking straight downwards onto xy plane, alpha 0, , y2 = y1. if @ 45 degrees, alpha pi/4 , y2 = 0.707 * y1 (approximately).
you can combine these 2 transformations into:
xnew = x * cos(theta) - y * sin(theta); ynew = cos(alpha) * (x * sin(theta) + y * cos(theta)); try few values of theta (between 0 , 0.5, in steps of 0.1) , alpha (similar range good). see if result.
maybe improve (in sense of "more useful") reply you?
objective-c osx core-graphics
No comments:
Post a Comment