PDA

View Full Version : Defining 3D Point


BoKirra
2008-12-08, 04:49 AM
Hi ALL,

I am going to drawing 3d line but I don't know how to define two 3D points.
Two points are relative to the insert point IPt.
Point 1: @(0,0,50)
Point 2: @(50,0,50)

The following is what I did.
Your helps would be much appreciated.

(defun c:TEST (/ IPt Pt1 Pt2)

(setq IPt (getpoint "\nselect Insert Point: "))

(setq
PT1 (polar IPt Angle & Distance)
PT2 (polar PT1 Angle & Distance)
) ;end setq

...

(princ)
)

'gile'
2008-12-08, 07:40 AM
Hi,

You can't use polar for this.
polar is 2d working (the specified angle is an angle on XY plane)

Doing @0,0,50 you specify a displacement, (0 0 50) can be considered as a vector.
So, the easy way is to add to each coordinates of IPt the corresponding coordinate of the vector:

(setq Pt1 (list (+ (car IPt) 0) (+ (cadr IPt) 0) (+ (caddr IPt) 50))
Pt2 (list (+ (car IPt) 50) (+ (cadr IPt) 0) (+ (caddr Ipt 50)))
)

This way is quite uggly and not so easy to read,
AutoLISP provides the mapcar fuction does the same job, you'd rather write:

(setq Pt1 (mapcar '+ IPt '(0 0 50))
Pt2 (mapcar '+ IPt '(50 0 50))
)

BoKirra
2008-12-09, 12:45 AM
Hi,
You can't use polar for this.
polar is 2d working (the specified angle is an angle on XY plane)


Thanks.
But what if Point 1 was known as:
1) angle = 30 degree relative to X axis;
2) y = 50;
3) z = 50;
instead of @(0,0,50)

'gile'
2008-12-09, 08:27 AM
Hi,

There're 3 ways to define a 3d point relative coordinates

1- @x,y,z
2- @distance<[angle about X axis],z (cylindric)
3- @distance<[angle about X axis]<[angle about XY plane] (spheric)

Assuming=:
- org is the orign point (@)
- pt the point to calculate
- p0 the projection of pt on the plane parallel to XY plane which contains org
x, y, z are coordinates
a1 is an angle about XY axis (radians)
a2 is an angle about XY plane (radians)

@x,y,z
(setq pt (mapcar '+ org (list x y z)))

@d<a1,z
(setq p0 (polar org a1 d)
pt (list (car p0) (cadr p0) (+ (caddr p0) z))
)

@d<a1<a2
(setq p0 (polar org a1 (* d (cos a2)))
pt (list (car p0) (cadr p0) (+ (caddr p0) (* d (sin a2))))
)

BoKirra
2008-12-11, 02:48 AM
Hi,

There're 3 ways to define a 3d point relative coordinates

1- @x,y,z
2- @distance<[angle about X axis],z (cylindric)
3- @distance<[angle about X axis]<[angle about XY plane] (spheric)

Assuming=:
- org is the orign point (@)
- pt the point to calculate
- p0 the projection of pt on the plane parallel to XY plane which contains org
x, y, z are coordinates
a1 is an angle about XY axis (radians)
a2 is an angle about XY plane (radians)

@x,y,z
(setq pt (mapcar '+ org (list x y z)))

@d<a1,z
(setq p0 (polar org a1 d)
pt (list (car p0) (cadr p0) (+ (caddr p0) z))
)

@d<a1<a2
(setq p0 (polar org a1 (* d (cos a2)))
pt (list (car p0) (cadr p0) (+ (caddr p0) (* d (sin a2))))
)

Thanks. It's great.