Jump to content

3D Polar


Jonathan Handojo

Recommended Posts

Hi again guys,

 

Does anyone have a function to return a 3D point resulting from the polar function, provided a 3D point, angle, distance, and a normal vector? (From WCS btw)

(the built-in polar function uses (0.0 0.0 1.0) as normal.)

 

I didn't actually want to post this as I felt like I'm close to the solution (though struggling like crazy), but so close yet so far.

 

Here's my pathetic attempt to this, provided that Z is not zero:

 

;; JH:3dpolar --> Jonathan Handojo
;; Returns a 3D point resulting from using the polar
;; function on a point rotating about a given normal
;; (polar uses the normal (0.0 0.0 1.0))
;; pt - point to calculate
;; ang - angle in radians
;; dist - displacement
;; norm - 3D vector determining the normal

(defun JH:3dpolar (pt ang dist norm)
  (setq vec (polar '(0 0 0) ang dist)
	vz (/ (- (apply '+ (mapcar '(lambda (x) (* (x norm) (x vec))) (list car cadr)))) (last norm))
	) 
  (mapcar '+ pt (mapcar '(lambda (x) (* x dist)) (vx1 (list (car vec) (cadr vec) vz))))
  )

;; Unit Vector  -  Lee Mac
;; Args: v - vector in R^2 or R^3

(defun vx1 ( v )
    (   (lambda ( n ) (if (equal 0.0 n 1e-10) nil (mapcar '/ v (list n n n))))
        (distance '(0.0 0.0 0.0) v)
    )
)

Thanks

Jonathan Handojo

Edited by Jonathan Handojo
Link to comment
Share on other sites

9 minutes ago, Lee Mac said:

(defun 3dpolar ( bpt ang dis nor )
    (trans (polar (trans bpt 0 nor) ang dis) nor 0)
)

 

Lol, why do you make it look so easy? And you figured out in a short time... Thanks again Lee

  • Funny 1
Link to comment
Share on other sites

A little too late:

(defun test (pt ang dist norm)
  (mapcar '+ pt (trans (polar '(0 0 0) ang dist) norm 0 T))
)

Of course the trans function defines a custom CS based on a single normal. The OP may not want to follow that algorithm.

Link to comment
Share on other sites

34 minutes ago, Roy_043 said:

A little too late:


(defun test (pt ang dist norm)
  (mapcar '+ pt (trans (polar '(0 0 0) ang dist) norm 0 T))
)

Of course the trans function defines a custom CS based on a single normal. The OP may not want to follow that algorithm.

 

That would work too. Nice!

 

The reason I'm asking this is because I'm making a routine with grread where coordinate systems can be anywhere.

 

Plus, if the origin of the UCS is not in plane with the object that you're modifying in the grread, it can screw up some. Which is why I just figured to use grread all related to WCS. It's also one reason why Lee's Align Text to Curve was acting up if the curve is not in plane with the UCS. I would understand it if your "VIEWDIR" is off because grread returns the coordinates of the mouse cursor on the construction plane, not the screen. You can try it here:

 

 

TestAlign.dwg

Link to comment
Share on other sites

I have not checked, but my guess is the trans function is inconsistent here.

The polar function measure the angle from Ox axis and trans function uses Arbitrary Axis Algorithm, which means you have no control over X axis.

 

Instead of normal vector, I'd use a direction vector d, if possible.

The result would be p+(unit d)*length

 

Edit: Trans can be used, but not like in the examples above. The selected, or calculated, direction 1,0,0 should be also transformed from WCS to normal and the polar angle adjusted accordingly.

Edited by Stefan BMR
Link to comment
Share on other sites

What about 1st principles using sin & cos work out X Y Z differences and then (setq p2 (mapcar '+ p1 (list X Y Z))) really have no idea with UCS Planes but makes sense.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...