POV-Ray : Newsgroups : povray.binaries.images : Math Help Request Server Time
18 Nov 2024 06:19:12 EST (-0500)
  Math Help Request (Message 1 to 3 of 3)  
From: Tim McMurdo
Subject: Math Help Request
Date: 28 Oct 2005 10:30:01
Message: <web.4362358e2d40991cacb32c570@news.povray.org>
I have a gun port cut into the hull of the ship. The port was created by
differencing a box from the hull. The box was created along the z axis and
is 900mm wide (+450 and -450 on the x axis). The box was then rotated 15
degrees on the y axis and translated to <12350,0,0>.

I need to use the trace function to locate the points on the hull that are
451mm either side of the center of the gunport opening.

1. What is the math involved in determining the angle from the z axis to the
points on either side of the opening? Do I shoot a trace at the center
first to determine the distance from <12350,0,0,0> to the center and then
use C2 = A2 + B2 and trig to figure the angles to the points on either
side?

2. Once I have the angle, how do I convert it to a vector that I can use in
trace?

Thanks,

Tim


Post a reply to this message


Attachments:
Download 'math_help.jpg' (18 KB)

Preview of image 'math_help.jpg'
math_help.jpg


 

From: Chris B
Subject: Re: Math Help Request
Date: 28 Oct 2005 15:07:58
Message: <4362770e$1@news.povray.org>
"Tim McMurdo" <jod### [at] wohrrcom> wrote in message 
news:web.4362358e2d40991cacb32c570@news.povray.org...
>I have a gun port cut into the hull of the ship. The port was created by
> differencing a box from the hull. The box was created along the z axis and
> is 900mm wide (+450 and -450 on the x axis). The box was then rotated 15
> degrees on the y axis and translated to <12350,0,0>.
>
> I need to use the trace function to locate the points on the hull that are
> 451mm either side of the center of the gunport opening.
>
> 1. What is the math involved in determining the angle from the z axis to 
> the
> points on either side of the opening? Do I shoot a trace at the center
> first to determine the distance from <12350,0,0,0> to the center and then
> use C2 = A2 + B2 and trig to figure the angles to the points on either
> side?
>
> 2. Once I have the angle, how do I convert it to a vector that I can use 
> in
> trace?
>
> Thanks,
>
> Tim
>

Hi Tim,

You could certainly do what you describe and perform the calculations (for 
the second part look up vrotate() in help)

But if I wanted to find points on either side of the such an opening, I'd 
tend to be lazy and let POV-Ray do the work.
If you just assign your tranformation a name, then you can apply it to your 
box and also to a couple of points that you can then use to fire rays 
parallel to the transformed line of the box and 451 units from its centre.

For example:

#include "transforms.inc"

#declare YourTransform = transform {rotate y*15 translate 12350*x};
#declare YourHull = difference {
  plane {-z, 100 pigment {color rgb <1,0,1>}}
  box {<-450,-450,-450><450,450,450> transform YourTransform pigment {color 
rgb <1,1,0>}}
}

#declare LeftNormal = <0,0,0>;
#declare LeftStartPoint  = vtransform(<-451,0,-500>, YourTransform);
#declare LeftTarget      = vtransform(<-451,0, 500>, YourTransform);
#declare LeftPosition = trace(YourHull, LeftStartPoint, 
LeftTarget-LeftStartPoint, LeftNormal);
#if (vlength(LeftNormal)!=0)
  #debug concat("Left point: ",vstr(3,LeftPosition,",",3,3),"\n")
#else
  #debug "Whoops. Missed on Left!"
#end

#declare RightNormal = <0,0,0>;
#declare RightStartPoint  = vtransform(< 451,0,-500>, YourTransform);
#declare RightTarget      = vtransform(< 451,0, 500>, YourTransform);
#declare RightPosition = trace(YourHull, RightStartPoint, 
RightTarget-RightStartPoint, RightNormal);
#if (vlength(LeftNormal)!=0)
  #debug concat("Right point: ",vstr(3,RightPosition,",",3,3),"\n")
#else
  #debug "Whoops. Missed on Right!"
#end

camera {location vtransform(<0,100,-1700>,YourTransform) look_at 
vtransform(<0,0,0>,YourTransform)}
light_source { <12000, 1000, -2000> color rgb 1}
object {YourHull }
sphere   {LeftPosition,20 pigment {color rgb <1,0,0>}}
cylinder {LeftStartPoint,LeftTarget,10 pigment {color rgb <0,1,1>}}
sphere   {RightPosition,20 pigment {color rgb <1,0,0>}}
cylinder {RightStartPoint,RightTarget,10 pigment {color rgb <0,1,1>}}


Regards,
Chris B.


Post a reply to this message

From: Tim McMurdo
Subject: Re: Math Help Request
Date: 31 Oct 2005 15:45:00
Message: <web.436681a3ef713d12395d82550@news.povray.org>
Chris,

Your code worked perfectly with very little modification to fit my model. I
made the effort to completely work out exactly what you were doing & I wish
I had written similar code for all of the hull openings. thanks for the
help.

Tim


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.